Perfect numbers: Difference between revisions
Content added Content deleted
Line 2,819: | Line 2,819: | ||
=={{header|PARI/GP}}== |
=={{header|PARI/GP}}== |
||
===Using built-in |
===Using built-in methods=== |
||
<syntaxhighlight lang="parigp"> |
<syntaxhighlight lang="parigp"> |
||
isPerfect(n)=sigma(n,-1)==2 |
isPerfect(n)=sigma(n,-1)==2 |
||
Line 2,829: | Line 2,829: | ||
Show perfect numbers |
Show perfect numbers |
||
<syntaxhighlight lang="parigp"> |
<syntaxhighlight lang="parigp"> |
||
forprime(p=2, 2281, |
forprime(p=2, 2281, |
||
Line 2,834: | Line 2,835: | ||
print(p"\t",(2^p-1)*2^(p-1)))) |
print(p"\t",(2^p-1)*2^(p-1)))) |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
faster alternative showing them still using built-in methods |
|||
<syntaxhighlight lang="parigp"> |
|||
[n|n<-[1..10^4],sigma(n,-1)==2] |
|||
</syntaxhighlight> |
|||
===Faster with Lucas-Lehmer test=== |
===Faster with Lucas-Lehmer test=== |
||
<syntaxhighlight lang="parigp">p=2;n=3;n1=2; |
<syntaxhighlight lang="parigp">p=2;n=3;n1=2; |