The Biggest Prime
February 8, 2013
It has been widely reported that a new “biggest prime” was found two weeks ago. The prime, which has 17,425,170 digits, is:
257,885,161 − 1
Your task is to write a program that displays all seventeen million digits of the biggest prime. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.
From the command line:
redirect to a file if you’d like. Produces 17,425,171 digits in under 5 seconds on my machine.
Using the Pari backend requires raising the Pari stacksize — I didn’t try it. Using the default Calc backend is quite slow as expected with very big numbers — I killed it after 7 minutes.
Fabrice Bellard’s solution to a smaller Mersene can be found here : http://bellard.org/mersenne.html
[…] Pages: 1 2 […]
Haskell:
The first attempt using Python 2.7 failed. It is no problem to make the prime, but printing it (or converting it to a string) takes more than 2 hours (and maybe never finishes). Using the gmpy library the time taken is 22 secs. It creates a file of about 17 MB.
[…] ¿cuáles son todas las cifras del primo 48 de Mersenne? En erl sitio Programming Praxis se reta a los lectores (programadores) a que generen los 17 millones de dígitos. Un programa […]
[…] el sitio https://programmingpraxis.com/2013/02/08/the-biggest-prime han publicado un reto para escribir los un poco más de 17 millones de dígitos que tiene el 48o […]
I had to use the GMP C Library.
There exists a function to specifically do this sort of thing. Here is my code in C :
Redirecting the big prime to a file produces a 16.6 Mb file on my machine. It runs in under 3 seconds on my old laptop with a Pentium 4 processor.
I decided to print it in hex. (-:
What I found out today is that Standard ML’s big integer library appears to be horrifically slow.
The code is:
[sourrcecode]
Control.Print.intinfDepth := 17500000;
IntInf.pow (LargeInt.fromInt 2, 57885161) – 1;
[/sourcecode]
It’s still running after about 5 hours.
[…] trying to solve the biggest prime programming praxis problem in C#. The problem is simple, print out or write to file the number: […]
Globules said
February 9, 2013 at 8:07 AM
Haskell: 1 main = print $ 2^57885161-1
581887266232246442….. Wrong!!