I'm trying to solve the biggest prime programming praxis problem in C#. The problem is simple, print out or write to file the number: 257,885,161 − 1 (which has 17,425,170 digits)
I have managed to solve it using the amazing GNU Multiple Precision Arithmetic Library through Emil Stevanof .Net wrapper
var num = BigInt.Power(2, 57885161) - 1;
File.WriteAllText("biggestPrime.txt", num.ToString());
Even if all the currently posted solutions use this library, to me it feels like cheating. Is there a way to solve this in managed code? Ideas? Suggestions?
PS: I have already tried using .Net 4.0 BigInteger but it never ends to compute (I waited 5 minutes but it is already a lot compared to 50 seconds of the GMP solution).
Currently, the largest known prime number is 282,589,933−1. This prime, along with the previous seven largest primes to be discovered, are known as Mersenne primes, named after the French mathematician Marin Mersenne (1588–1648).
97 is: the 25th prime number (the largest two-digit prime number in base 10), following 89 and preceding 101.
List of Prime Numbers Up to 100. 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97.
If you do the math, the new largest-known prime is a whopping 24,862,048 digits long.
It's also more a cheat than a solution but I solved this using the IntX library
IntX.Pow(2, 57885161, MultiplyMode.AutoFht) - 1;
It ran approximately 6 minutes. Still this is not a real answer though. Would be interesting to see something "real".
EDIT: Using a C# Stopwatch I figured that the calculation only took 5 seconds, it's the process of ToString that takes extremely long.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With