Example #1
0
'''
Sieves?
'''

import euler

N = 10**6
totient = euler.phisieve(N+1)

def smartTotient(N):
    return sum([ totient[n] for n in range(1,N+1) ])-1

print smartTotient(N)


Example #2
0
'''
Sieves?
'''

import euler

N = 10**6
totient = euler.phisieve(N + 1)


def smartTotient(N):
    return sum([totient[n] for n in range(1, N + 1)]) - 1


print smartTotient(N)
Example #3
0
import euler

print 'init'
N = 10**7#2*10**7
phi = euler.phisieve(N)
print 'init.'

def relevant(i):
    a = euler.intToSeq(i)
    a.sort()
    b = euler.intToSeq(phi[i])
    b.sort()
    return a==b

vbest = None
nbest = None
for n in xrange(2,N):
    if relevant(n):
        v = n/float(phi[n])
        if vbest == None or v < vbest:
            vbest = v
            nbest = n
            print vbest,nbest,phi[n]

print 'soln',nbest