Example #1
0
from eulerlib import cmpf, gcd

N = 12000 

f1 = (1,3)
f2 = (1,2)

c = 0
for d in xrange(1,N+1):
	for n in xrange(d/3,d/2+1):
		if gcd(n,d) == 1:
			f = (n,d)
			if cmpf(f,f1) > 0 and cmpf(f,f2) < 0:
				c += 1

print c
Example #2
0
    while n <= N:
        m = n
        s = 0
        while m % p == 0:
            s += 1
            m /= p

        prime_factors[n].append((p, s))
        n += p

#calculate Euler Phi function
for p in all_primes:
    n = p
    prev = phi[1]
    while n <= N:
        phi[n] = n - n / p
        prev = n
        n *= p


def euler_phi(n):
    if phi[n] < 0:
        phi[n] = 1
        for f in prime_factors[n]:
            phi[n] *= phi[f[0]**f[1]]
    return phi[n]


ratios = [(n, euler_phi(n)) for n in xrange(1, N + 1)]
print reduce(lambda r1, r2: r1 if cmpf(r1, r2) > 0 else r2, ratios)[0]
Example #3
0
	n = p
	while n <= N:
		m = n
		s = 0
		while m % p == 0:
			s += 1
			m /= p

		
		prime_factors[n].append((p,s))
		n += p

#calculate Euler Phi function
for p in all_primes:
	n = p
	prev = phi[1]
	while n <= N:
		phi[n] = n - n/p
		prev = n
		n *= p

def euler_phi(n):
	if phi[n] < 0:
		phi[n] = 1
		for f in prime_factors[n]:
			phi[n] *= phi[f[0]**f[1]]
	return phi[n]

ratios = [(n,euler_phi(n)) for n in xrange(1,N+1)]
print reduce(lambda r1, r2: r1 if cmpf(r1,r2) > 0 else r2, ratios)[0]