Skip to content

Instantly share code, notes, and snippets.

@jakedobkin
Created January 3, 2012 17:42
Show Gist options
  • Save jakedobkin/1556019 to your computer and use it in GitHub Desktop.
Save jakedobkin/1556019 to your computer and use it in GitHub Desktop.
Problem 95 in Progress- Full Divisor Set
# http://projecteuler.net/problem=95
# brute force sieve
n=1000000
sequences = {}
divisorSum = [1]*(n+1)
for i in range (2,n/2+1):
j = 2*i
while j<=n:
divisorSum[j]+=i
j = j+i
def roundfadd(n,array,p):
if n in sequences:
return sequences[n][0], sequences[n][1],n
if n > 1000000 or n == 1:
return 0,0
elif divisorSum[n] in array:
# minor correction here for the way they're defining the loop count-
# if it doesn't repeat from the first number in array chain, you
# have to correct by subtracting the index where the loop actually begins
return p-array.index(divisorSum[n]),min(array[array.index(divisorSum[n])::])
else:
p += 1
array.append(divisorSum[n])
return roundfadd(divisorSum[n],array,p)
max = 0,0
for x in range (2,n):
sequences[x] = roundfadd(x,[],0)
if sequences[x][0] > max[0]:
max = sequences[x]
print max
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment