Perfect numbers: Difference between revisions

Content added Content deleted
Line 618: Line 618:
=={{header|PARI/GP}}==
=={{header|PARI/GP}}==
Uses built-in method. Faster tests would use the LL test for evens and myriad results on OPNs otherwise.
Uses built-in method. Faster tests would use the LL test for evens and myriad results on OPNs otherwise.
<lang>isPerfect(n)=sigma(n,-1)==2</lang>
<lang parigp>isPerfect(n)=sigma(n,-1)==2</lang>
Show perfect numbers
Show perfect numbers
<lang>forprime(p=2, 2281,
<lang parigp>forprime(p=2, 2281,
if(isprime(2^p-1),
if(isprime(2^p-1),
print(p"\t",(2^p-1)*2^(p-1))))</lang>
print(p"\t",(2^p-1)*2^(p-1))))</lang>
Faster with Lucas-Lehmer test
Faster with Lucas-Lehmer test
<lang>p=2;n=3;n1=2;
<lang parigp>p=2;n=3;n1=2;
while(p<2281,
while(p<2281,
if(isprime(p),
if(isprime(p),
Line 635: Line 635:
</lang>
</lang>
output
output
<lang>(2^2-1)2^(2-1)= 6
<pre>(2^2-1)2^(2-1)= 6
(2^3-1)2^(3-1)= 28
(2^3-1)2^(3-1)= 28
(2^5-1)2^(5-1)= 496
(2^5-1)2^(5-1)= 496
Line 644: Line 644:
(2^31-1)2^(31-1)= 2305843008139952128
(2^31-1)2^(31-1)= 2305843008139952128
(2^61-1)2^(61-1)= 2658455991569831744654692615953842176
(2^61-1)2^(61-1)= 2658455991569831744654692615953842176
(2^89-1)2^(89-1)= 191561942608236107294793378084303638130997321548169216</lang>
(2^89-1)2^(89-1)= 191561942608236107294793378084303638130997321548169216</pre>


=={{header|Perl}}==
=={{header|Perl}}==