Beispiel #1
0
        public long Solve(string textfile = "")
        {
            primes = PrimesUtil.SetUpPrimes(10000000).ToHashSet();

            var maxRun  = 0;
            var maxRunA = 0;
            var maxRunB = 0;

            for (int b = 2; b < 1000; ++b)
            {
                if (primes.Contains(b))
                {
                    for (int a = -999; a < 1000; ++a)
                    {
                        if (primes.Contains(1 + b + a))
                        {
                            var run = MaxPrimeRun(a, b) + 2;
                            if (run > maxRun)
                            {
                                maxRun  = run;
                                maxRunA = a;
                                maxRunB = b;
                            }
                        }
                    }
                }
            }
            return(maxRunA * maxRunB);
        }
Beispiel #2
0
        public long Solve(string textfile = "")
        {
            primes = PrimesUtil.SetUpPrimes(maxToCheck);

            List <int> abundantNums = new List <int>(500);

            bool[] sumOfTwoAbundants = new bool[maxToCheck];

            FindAllAbundantNums(maxToCheck, abundantNums);

            foreach (int abundantNum in abundantNums)
            {
                for (int i = 0; i < abundantNums.Count; ++i)
                {
                    var sum = abundantNum + abundantNums[i];
                    if (sum < maxToCheck)
                    {
                        sumOfTwoAbundants[sum] = true;
                    }
                }
            }

            var totalNonAbundants = 0;

            for (int i = 1; i < maxToCheck; ++i)
            {
                if (!sumOfTwoAbundants[i])
                {
                    totalNonAbundants += i;
                }
            }
            return(totalNonAbundants);
        }