Пример #1
0
        protected override string Solve()
        {
            int result = 0;

            IEnumerable <long> primes = PrimeHelper.GeneratePrimes(999999);

            foreach (long prime in primes)
            {
                IEnumerable <long> rotations = NumberHelper.GetRotations(prime);

                int primeCount = 0;

                foreach (long rotation in rotations)
                {
                    if (PrimeHelper.IsPrime(rotation))
                    {
                        primeCount++;
                    }
                }

                if (primeCount == rotations.Count())
                {
                    result++;
                }
            }

            return(result.ToString("0"));
        }
Пример #2
0
        protected override string Solve()
        {
            long result = 0;

            IEnumerable <long> primes = PrimeHelper.GeneratePrimes(1999999);

            result = primes.Sum();

            return(result.ToString("0"));
        }
Пример #3
0
        protected override string Solve()
        {
            //stab in the dark here, the 10001st prime is probably below 10million?

            //could check numbers incrementally as prime or not, but a Sieve would be faster still

            IList <long> primes = PrimeHelper.GeneratePrimes(10000000).ToList();

            primes.OrderBy(o => o);

            return(primes[10000].ToString("0"));
        }
Пример #4
0
        protected override string Solve()
        {
            int hitCount = 0;
            int result   = 0;

            IList <long> primes = PrimeHelper.GeneratePrimes(100000000).ToList();

            primes.Remove(2);
            primes.Remove(3);
            primes.Remove(5);
            primes.Remove(7);

            for (int i = 0; i < primes.Count; i++)
            {
                bool primeCheck = true;

                int n = i;

                //check primality right to left
                do
                {
                    if (PrimeHelper.IsPrime(n) == false)
                    {
                        primeCheck = false;
                        break;
                    }
                    n /= 10;
                } while (n > 0);

                //check primality left to right
                if (primeCheck) //don't bother if already failed right to left
                {
                    n = i;
                    int modulo = (int)Math.Pow(10, (NumberHelper.GetDigits(n).Count() - 1));
                    do
                    {
                        n %= modulo;

                        modulo = (int)Math.Pow(10, (NumberHelper.GetDigits(n).Count() - 1));

                        if (PrimeHelper.IsPrime(n) == false)
                        {
                            primeCheck = false;
                            break;
                        }
                    } while (modulo != 1);
                }


                if (primeCheck)
                {
                    result += i;
                    hitCount++;
                }
                if (hitCount == 11)
                {
                    return(result.ToString("0"));
                }
            }

            return("none found");
        }