Skip to content

Instantly share code, notes, and snippets.

@jakedobkin
Created December 24, 2011 02:07
Show Gist options
  • Select an option

  • Save jakedobkin/1515938 to your computer and use it in GitHub Desktop.

Select an option

Save jakedobkin/1515938 to your computer and use it in GitHub Desktop.
Euler 70- a bit slow
factors = [1]*10000001
for i in range (0,len(factors)):
factors[i]=i
# set up prime sieve to n
n=10000000
myPrimes = [True]*(n+1)
last = 0
for i in range (2,n):
if myPrimes[i] == True:
j = 2*i
while j<=n:
myPrimes[j]=False
factors[j]=factors[j]*(1.0-(1.0/i))
j=j+i
min_ratio = 10
min_n = 0
for n in range (8000000,10000000):
if myPrimes[n]!=True:
if len(str(int(factors[n]))) == len(str(n)):
testa = []
for p in range (0,len(str(int(factors[n])))):
testa.append(str(int(factors[n]))[p:p+1])
testa.sort()
testb = []
for q in range (0,len(str(n))):
testb.append(str(n)[q:q+1])
testb.sort()
if testa == testb:
# print n,factors[n],n/factors[n]
if n/factors[n] < min_ratio:
min_ratio = n/factors[n]
min_n=n
print min_n,min_ratio
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment