49 lines
991 B
Python
49 lines
991 B
Python
#!/usr/bin/env python3
|
|
|
|
from itertools import combinations
|
|
from operator import mul
|
|
from functools import reduce
|
|
|
|
def factorize(n, primes):
|
|
return [p for p in primes if not n%p]
|
|
|
|
def totient(factors, n):
|
|
r = 0
|
|
for i in range(1, len(factors)+1):
|
|
for f in combinations(factors, i):
|
|
r += (-1)**i * (n // reduce(mul, f))
|
|
return n + r
|
|
|
|
def get_primes(n):
|
|
sieve = [False] * n
|
|
r = []
|
|
for p in range(2, n):
|
|
if sieve[p]:
|
|
continue
|
|
r.append(p)
|
|
for i in range(p**2, n, p):
|
|
sieve[i] = True
|
|
return r
|
|
|
|
a, b = 15499, 94744
|
|
primes = get_primes(100)
|
|
n = 1
|
|
for i, p in enumerate(primes):
|
|
n *= p
|
|
t = totient(primes[:i+1], n)
|
|
if t*b < (n-1)*a:
|
|
break
|
|
else:
|
|
print("Not found")
|
|
quit()
|
|
|
|
n //= primes[i]
|
|
factors = primes[:i]
|
|
|
|
for i in range(2, 100):
|
|
t = totient(set(factors + factorize(i, primes)), n*i)
|
|
if t*b < (n*i - 1) * a:
|
|
print(n*i)
|
|
quit()
|
|
print("Not found")
|