Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 3869

Other programming languages • Re: Extracting the values of 'Perfect Number' 1 to 52

$
0
0
For some things Mathematica is nice, for others it is too restricted.

PARI/GP is fully open source and has no restrictions.
Here are the 52 Mersenne prime exponents:
https://gist.github.com/Hermann-SW/f44c ... c2fd010e21

With them you can easily compute all 52 associated perfect numbers.
#digits() for number of decimal digits is very slow.
I used #binary() to output the binary length of the 52 perfect numbers.
Took 21 seconds in total on Pi5 — I had to increase parisizemax in /etc/gprc from 2200M to 3000M:
pi@raspberrypi5:~ $ gp -q mpe.gp
? c=1;foreach(mpe,t,print(c,": ",#binary(2^(t-1)*(2^t-1)));c+=1)
....
P.S:
If you want to print the numbers, shorter and faster is as hexadecimal numbers:

Code:

printf("%#x",2^(t-1)*(2^t-1)));
PARI/GP

Code:

x=17million_hex_digit_number; 
is 13x faster than

Code:

x=20million_decimal_digit_number; 
https://gist.github.com/Hermann-SW/1aa0 ... nt-5286782
Thank you ,"PARI/GP is fully open source and has no restrictions.". It is amazing that , the decimal digits extraction of perfect number#52 ,took less than 90 seconds using the following "pn52.gp" file

Code:

\\ Compute the 52th perfect numberp =136279841 ; \\ Exponent of the 52nd Mersenne primeperfect_number = 2^(p-1) * (2^p - 1);\\ Write the perfect number's digits to a filewrite("perfect_number_52.txt", Str(perfect_number));
in 90s ,82,048,640 digits were written to the file ' perfect_number_52.txt '.
pn52_pari_gp_rPi4.jpg

Statistics: Posted by geev03 — Mon Nov 18, 2024 6:33 pm



Viewing all articles
Browse latest Browse all 3869

Trending Articles