// Gives 76576500 and takes 1.3 seconds public static double FirstRun() { const int divisorCount = 1000; double value = 0; double previousTriangleMax = 0; var divisors = new HashSet <double>(); var maxDivisors = new HashSet <double>(); while (true) { previousTriangleMax++; value += previousTriangleMax; divisors.Clear(); // Skip if not divisible by 2 if (Math.Abs(value % 10) > double.Epsilon) { continue; } divisors.Add(1); divisors.Add(value); // Get all primes less than value var root = Math.Sqrt(value); //If sqrt is whole add to divisors if (Math.Abs(Math.Floor(root) - root) < double.Epsilon) { divisors.Add(root); } var primes = PrimeHelper.GetAllPrimesLessThanValue(Math.Ceiling(root)); foreach (var prime in primes) { for (var i = prime; i <= root; i += prime) { if (!(Math.Abs(value % i) < double.Epsilon)) { continue; } divisors.Add(i); divisors.Add(value / i); } } if (divisors.Count > maxDivisors.Count) { var array = new double[divisors.Count]; divisors.CopyTo(array); maxDivisors = array.ToHashSet(); } if (divisors.Count >= divisorCount) { return(value); } } }