Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def factorize(n):
- factors = []
- while n % 2 == 0:
- factors.append(2)
- n = int(n / 2)
- for b in range(3, int(n ** 0.5) + 1, 2):
- while n % b == 0:
- n = int(n / b)
- factors.append(b)
- if n > 2:
- factors.append(int(n))
- return set(factors)
- def totient(n):
- coprimes = n
- for x in factorize(n):
- coprimes *= (1 - (1 / x))
- return int(coprimes)
- def primes_sieve(limit):
- a = [True] * limit
- a[0] = a[1] = False
- for (i, isprime) in enumerate(a):
- if isprime:
- yield i
- for n in range(i * i, limit, i):
- a[n] = False
- answer = 0
- for b in list(primes_sieve(40*10**6)):
- print(b)
- original = b
- for c in range(24):
- b = totient(b)
- if (b == 1) and (c != 23):
- break
- if (b == 1) and (c == 23):
- answer += original
- print(answer)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement