Can anyone tell me how to find largest perfect number less than 10000 in maple? Actually, I know how to find all the perfect numbers less than or equal to 10000 but I don't know how to find the largest one within the same code?
Asked
Active
Viewed 211 times
2 Answers
4
Well if you know how to find them all, I suppose you use a loop.
So before your loop add a variable $max=0$. During the loop, for each perfect number $p$ you find, check if $p>max$ and if it is, then do $max=p$.
The value of $max$ after the end of the loop will be the greatest number found ;)
Dolma
- 1,410
-
... and this question belongs in a coding forum, not in a math forum ... – GEdgar Apr 16 '13 at 15:13
-
Yes you're right ... – Dolma Apr 16 '13 at 20:38
3
You could use the fact that all known perfect numbers are of the form $n=2^{p-1}(2^p-1)$ where $2^p-1$ is a prime (and hence $p$ is a prime.)
This means that $2n=(2^p)^2-2^p = (2^p-\frac{1}{2})^2-1/4$. So $2^{p}-1$ only needs to be checked up to the value of $\sqrt{20000}\approx 142$, or $p$ only needs to be checked up to $p=7$. Indeed, $127=2^7-1$ is prime, so $2^{6}(2^7-1)=8128$ is the perfect number you are looking for.
Thomas Andrews
- 177,126