Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write the biggest prime

Tags:

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).

like image 318
marcob Avatar asked Feb 10 '13 11:02

marcob


People also ask

Which is the biggest prime?

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).

Which is the biggest two prime number?

97 is: the 25th prime number (the largest two-digit prime number in base 10), following 89 and preceding 101.

What is the largest prime of 100?

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.

How many digits is the biggest prime?

If you do the math, the new largest-known prime is a whopping 24,862,048 digits long.


1 Answers

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.

like image 150
reinder Avatar answered Oct 02 '22 15:10

reinder