How to get decimal form of largest known prime?

David M. Cooke cookedm+news at physics.mcmaster.ca
Mon Jun 14 22:01:52 CEST 2004


At some point, "Tim Peters" <tim.one at comcast.net> wrote:

> There are some GMP wrappers for Python.  Using Marc-Andre Lemburg's mxNumber
> wrapper (which is maximally convenient for me on Windows, since it includes
> a precompiled-for-Windows GMP), the OP's task is spelled like so:
>
>>>> from mx.Number import *
>>>> Integer(2)**24036583 - 1
>
> That does call mpz_pow_ui() and mpz_get_str() (with base=10) under the
> covers.
>
> Since I typed that in, the process has accumulated 59 CPU minutes, with no
> output yet.
>
> Curiously,
>
>>>> x = Integer(2)**24036583 - 1
>
> consumes 112 CPU seconds on its own, while the straight Python
>
>>>> x = 2**24036583 - 1
>
> consumes only 2 CPU seconds -- so Python is 50+ times faster than this GMP
> for the computational part.

Interesting, because with gmpy (on a 32-bit AMD64 machine running Linux):

>>> import gmpy
>>> x = gmpy.mpz(2)**24036583-1

is almost instantaneous, whereas the straight Python takes a second.

But then with gmpy I get
>>> print x
Segmentation fault

so I can't win here :-)

-- 
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke
|cookedm(at)physics(dot)mcmaster(dot)ca



More information about the Python-list mailing list