Beispiel #1
0
        public static long Solution()
        {
            long solution  = 0;
            var  stopwatch = new Stopwatch();

            stopwatch.Start();
            var previousTime = 0.0;
            var currentTime  = 0.0;

            var count     = 0;
            var solutions = new List <long>();

            for (int i = 7; count < limit; i++)
            {
                var order = UtilityFunctions.MultiplicativeOrder(10, 9 * i);
                if (order > 0 && (i - 1) % order == 0 && !UtilityFunctions.IsPrime(i))
                {
                    count    += 1;
                    solution += i;
                    solutions.Add(i);
                    Console.Write($"{ i}, ");
                }
            }
            currentTime = stopwatch.ElapsedMilliseconds;
            Console.WriteLine($"Solution took {currentTime - previousTime} seconds.");
            Console.WriteLine(solutions.ToArray());
            return(solution);
        }
Beispiel #2
0
        public static long Solution()
        {
            long solution  = 0;
            var  stopwatch = new Stopwatch();

            stopwatch.Start();
            var previousTime = 0.0;
            var currentTime  = 0.0;

            for (int i = 1; true; i++)
            {
                var p = 3 * i * i + 3 * i + 1;
                if (p > limit)
                {
                    break;
                }
                if (UtilityFunctions.IsPrime(p))
                {
                    solution += 1;
                    // Console.WriteLine($"{i} -> {p}");
                }
            }
            currentTime = stopwatch.ElapsedMilliseconds;
            Console.WriteLine($"Solution took {currentTime - previousTime} milliseconds.");

            return(solution);
        }
        public static long Solution()
        {
            long solution = 0;
            var  primes   = UtilityFunctions.Primes(8000);
            var  residues = new List <long> {
                1, 3, 7, 9, 13, 27
            };

            for (long num = 10; num < limit; num += 10)
            {
                if (num % 3 == 0 || (num % 7 != 3 && num % 7 != 4) || num % 13 == 0)
                {
                    continue;
                }
                bool skipNum = false;
                for (int i = 3; i < primes.Count; i++)
                {
                    long p = primes[i];
                    if (p > num * num)
                    {
                        break;
                    }
                    var r = num % p;
                    foreach (var s in residues)
                    {
                        if ((r * r + s) % p == 0)
                        {
                            skipNum = true;
                            break;
                        }
                    }
                    if (skipNum)
                    {
                        break;
                    }
                }
                if (skipNum)
                {
                    continue;
                }
                var nSquared = num * num;
                if (UtilityFunctions.IsPrime(nSquared + 1) &&
                    UtilityFunctions.IsPrime(nSquared + 3) &&
                    UtilityFunctions.IsPrime(nSquared + 7) &&
                    UtilityFunctions.IsPrime(nSquared + 9) &&
                    UtilityFunctions.IsPrime(nSquared + 13) &&
                    UtilityFunctions.IsPrime(nSquared + 27) &&
                    !UtilityFunctions.IsPrime(nSquared + 19) &&
                    !UtilityFunctions.IsPrime(nSquared + 21))
                {
                    solution += num;
                    Console.WriteLine(num);
                }
            }

            return(solution);
        }
Beispiel #4
0
        private static bool IsStrongHarshad(long n)
        {
            var digitSum = UtilityFunctions.DigitSum(n);

            if (n % digitSum != 0)
            {
                return(false);
            }
            if (!UtilityFunctions.IsPrime(n / digitSum))
            {
                return(false);
            }
            return(true);
        }
Beispiel #5
0
        public static long Solution()
        {
            long           solution = 0;
            HashSet <long> strongTruncatableHarshads;

            var rightTruncatableHarshads = RightTruncatableHarshads(limit, out strongTruncatableHarshads);

            foreach (var s in strongTruncatableHarshads)
            {
                foreach (var i in new[] { 1, 3, 7, 9 })
                {
                    var n = 10 * s + i;
                    if (UtilityFunctions.IsPrime(n))
                    {
                        solution += n;
                    }
                }
            }

            return(solution);
        }