Created
January 3, 2012 17:42
-
-
Save jakedobkin/1556019 to your computer and use it in GitHub Desktop.
Problem 95 in Progress- Full Divisor Set
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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