euler/python/e130.py

33 lines
677 B
Python
Raw Normal View History

2024-04-17 13:42:34 +02:00
from math import gcd
from lib_prime import is_prime_rabin_miller
def r_modulo_closed_form(n, m):
assert n > 0 and m > 0
return ((pow(10, n, 9 * m) - 1) // 9) % m
def a_special(n):
k = n - 1
if r_modulo_closed_form(k, n) == 0:
return k
return None
def euler_130():
c, r = 0, 0
for n in range(2, 10**9):
if gcd(n, 10) == 1 and not is_prime_rabin_miller(n):
if a_special(n) is not None:
r += n
c += 1
if c == 25:
break
return r
if __name__ == "__main__":
solution = euler_130()
print("e130.py: " + str(solution))
assert(solution == 149253)