Jump to content

Euler 21

Wictorian

I really need help with this one, I wrote this script but it returns wrong answer.

ans = 0
def sumOf(l):
    x = 0
    for i in l:
        x += i
    return (x)
def d(x):
    y = []
    for i in range(x-1):
        if x % (i+1) == 0:
            y.append(i+1)
    return(sumOf(y))

index=0
while(index<10000):
    index+=1
    a = d(index)
    if index == d(a):
        ans += a+index
print(ans)

 

Link to comment
Share on other sites

Link to post
Share on other sites

There are a few numbers that you sum twice.

 

ans = 0
for i in range(1, 10_000):
    a = d(i)
    b = d(a)

    if(b == i and a != b):
        ans += i

print(ans)

 

ಠ_ಠ

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×