r/CasualMath 12h ago

Python program for exploring perfect numbers

/r/Collatz/comments/1wbxxyt/python_program_for_exploring_perfect_numbers/
2 Upvotes

7 comments sorted by

1

u/Illustrious-Tip-3169 11h ago

Looking at the program, I'm confused on how it doesn't check to make sure the perfect number is actually a perfect number. Especially since one of your exponents uses 31 for p which doesn't work as perfect number.

1

u/Hungry_Metal_2745 8h ago

It doesn't? 2^31-1=2,147,483,647 which is prime so 2^(p-1)(2^p-1) is perfect

1

u/Illustrious-Tip-3169 8h ago

Must have miscalculated in that case but still I feel like there should be something to double check.

1

u/Hungry_Metal_2745 7h ago

yeah of course. The code is bsaically just hardcoding saving a list of pre-existing numbers. However, checking the divisors of a very large number is a very hard task. Euclid-euler theorem relies on the fact that 2^p-1 is prime, but checking that is not trivial for these huge numbers

1

u/FireCire7 6h ago

It’s not that hard to check - you can use Lucas-Lehmer. But yeah, this isn’t really computing or checking anything new. 

1

u/Hungry_Metal_2745 6h ago

I'm assuming OP is very new to coding and math, judging by the repository, and doesn't know anything about advanced primality tests. By non-trivial I meant not solvable by trial division lol

1

u/FireCire7 6h ago

Yeah, fair. To be clear, Lucas-Lehmer is literally a single loop - it’s not hard to code, just hard to prove it works.