How to get decimal form of largest known prime?

Daniel Yoo dyoo at hkn.eecs.berkeley.edu
Thu Jun 10 18:29:48 EDT 2004


Claudio Grondi <claudio.grondi at freenet.de> wrote:
: According to latest news the largest known prime is:
:                  2**24036583 - 1
: (right?)

: Do someone of you know how long would it take on
: a 2.8 GHz Pentium 4 machine to write a  _decimal_  form
: (hexadecimal form can be written in less than one second)
: of this prime to a file and what should be the Python code
: to use for it?

Hi Claudio,


Let's see... how many digits would it be?

###
>>> def digits(n):
...     return int(math.log(n) / math.log(10)) + 1
...
>>> x = 2**2436583 - 1
>>> digits(x)
733485
###

Ok, that doesn't sound too bad at all.  It's about 750,000 digits long.


It's actually not difficult to get the last decimal digit of this
humongous number:

###
>>> x % 10
7L
###


It's also not too difficult to get the second to last digit of this
number:

###
>>> (x / 10) % 10
0L
###

At least we can figure out that the number ends with a '07'.  If we
continue this way, we can quickly get the other digits.


Hope this helps!



More information about the Python-list mailing list