Project Euler #21: Amicable numbers

  • + 0 comments

    easy sol

    def divi_sum(n):
        r_sum=0
        for i in range(1,int(n**0.5)+1):
            if n%i==0:
                r_sum+=i+n//i
        if int(n**0.5)==n**0.5:
            r_sum+=-int(n**0.5)
        r_sum+=-n
        return r_sum
    
    req_numbers={}
    our_sum=0
    for i in range(1,10**5):
        req_numbers[i]=our_sum
        x=divi_sum(i)
        if x!=i and i==divi_sum(x):
            our_sum+=i
            
    for _ in range(int(input())):
        no=int(input())
        print(req_numbers[no])