2019-07-18 20:23:44 +02:00
|
|
|
from lib_misc import gcd
|
|
|
|
from lib_misc import get_digit_count
|
|
|
|
|
|
|
|
|
|
|
|
def add_fractions(n1, d1, n2, d2):
|
|
|
|
d = d1 * d2
|
|
|
|
n1 = n1 * (d // d1)
|
|
|
|
n2 = n2 * (d // d2)
|
|
|
|
n = n1 + n2
|
|
|
|
p = gcd(n, d)
|
|
|
|
return (n // p, d // p)
|
|
|
|
|
|
|
|
|
|
|
|
def next_expension(n, d):
|
|
|
|
n, d = add_fractions(1, 1, n, d)
|
|
|
|
return add_fractions(1, 1, d, n)
|
|
|
|
|
2019-07-18 03:29:59 +02:00
|
|
|
|
|
|
|
def euler_057():
|
2019-07-18 20:23:44 +02:00
|
|
|
c = 0
|
|
|
|
n, d = (3, 2)
|
|
|
|
for i in range(1000):
|
|
|
|
if get_digit_count(n) > get_digit_count(d):
|
|
|
|
c += 1
|
|
|
|
n, d = next_expension(n, d)
|
|
|
|
return c
|
2019-07-18 03:29:59 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
print("e057.py: " + str(euler_057()))
|
2019-07-18 20:23:44 +02:00
|
|
|
assert(euler_057() == 153)
|