public void Calculate(int divNum) { PrimeCalculator primeCalc = new PrimeCalculator(); primes_ = primeCalc.GetFirstNPrimes(divNum); povers_ = new List<int>(); nextMultiple_ = new SortedList<BigInt, int>(); for (int i = 0; i < primes_.Count; i++) { povers_.Add(0); nextMultiple_.Add(primes_[i], i); } BigInt result = 1; Console.WriteLine("start"); for (int i = 0; i < divNum; i++) { if (i%10000==0) Console.WriteLine(i); var key = nextMultiple_.Keys[0]; var minPrime = nextMultiple_[key]; //result *= key; int pow = povers_[minPrime]; povers_[minPrime] = (pow + 1) * 2 - 1; int nextPow = (povers_[minPrime] + 1) * 2 - 1; BigInt newValue = 1; for (int d = 0; d < nextPow - povers_[minPrime]; d++) newValue *= primes_[minPrime]; nextMultiple_.RemoveAt(0); nextMultiple_.Add(newValue, minPrime); } for (int i = 0; i < primes_.Count; i++) { if (i % 10000 == 0) Console.WriteLine(i); BigInt primMul = 1; for (int j = 0; j < povers_[i]; j++) primMul *= primes_[i]; if (primMul > 1) { result *= primMul; result %= 500500507; } } Console.WriteLine(result % 500500507); }