예제 #1
0
파일: Euler72.py 프로젝트: pfhayes/euler
# Find the number of reduced proper fractions
# where the denominator is less than 1000000

from useful import phi

tot = 0

for i in range(2, 1000001):
    tot += phi(i)
print tot
예제 #2
0
파일: Euler69.py 프로젝트: pfhayes/euler
# then (n^m) / phi(n^m) is constant for all m >= 1

from useful import PrimeList, phi

primes = PrimeList(1000001)
cands = set(range(2,1000001))

print "Ready!"

for p in primes :
	temp = p
	while temp < 1000001 :
		cands.remove(temp)
		temp *= p

for c in range(2,1001):
	temp = c
	temp *= c
	while temp < 1000001 :
		cands.discard(temp)
		temp *= c

ma = 0
best = 0
for cand in reversed(list(cands)) :
	val = float(cand) / phi(cand)
	if val > ma :
		ma = val
		best = cand
		print best