How to resolve the algorithm Perfect numbers step by step in the PARI/GP programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Perfect numbers step by step in the PARI/GP programming language
Table of Contents
Problem Statement
Write a function which says whether a number is perfect.
A perfect number is a positive integer that is the sum of its proper positive divisors excluding the number itself. Equivalently, a perfect number is a number that is half the sum of all of its positive divisors (including itself).
Note: The faster Lucas-Lehmer test is used to find primes of the form 2n-1, all known perfect numbers can be derived from these primes using the formula (2n - 1) × 2n - 1. It is not known if there are any odd perfect numbers (any that exist are larger than 102000). The number of known perfect numbers is 51 (as of December, 2018), and the largest known perfect number contains 49,724,095 decimal digits.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Perfect numbers step by step in the PARI/GP programming language
Source code in the pari/gp programming language
isPerfect(n)=sigma(n,-1)==2
isPerfect(n)=sigma(n)==2*n
forprime(p=2, 2281,
if(isprime(2^p-1),
print(p"\t",(2^p-1)*2^(p-1))))
[n|n<-[1..10^4],sigma(n,-1)==2]
p=2;n=3;n1=2;
while(p<2281,
if(isprime(p),
s=Mod(4,n);
for(i=3,p,
s=s*s-2);
if(s==0 || p==2,
print("(2^"p"-1)2^("p"-1)=\t"n1*n"\n")));
p++; n1=n+1; n=2*n+1)
You may also check:How to resolve the algorithm Averages/Arithmetic mean step by step in the Plain English programming language
You may also check:How to resolve the algorithm Comments step by step in the Joy programming language
You may also check:How to resolve the algorithm ABC problem step by step in the Maple programming language
You may also check:How to resolve the algorithm Strip a set of characters from a string step by step in the SAS programming language
You may also check:How to resolve the algorithm Magnanimous numbers step by step in the Mathematica/Wolfram Language programming language