re: Write a script to find "Perfect Numbers" VIEW POST

FULL DISCUSSION
 

Inspired from programming-algorithms.net/article...
Takes less than 1sec to get to 137438691328 but can't find easily 2305843008139952128

from math import sqrt
def perfect(n) :
    s = 1
    rac = int(sqrt(n))
    for k in range(2, rac+2) :
        if n%k == 0 :
            s += k + n//k
    return s == n
def f(x) :
    return (2**(x-1))*((2**x)-1)
n = 137438691329
m = 1
res = []
while True :
    val = f(m)
    print(val)
    if perfect(val) :
        res.append(val)
    m+=1
    if val > n :
        break
print(res)
 
code of conduct - report abuse