#! /usr/bin/env python3 """ pe26.py https://mind.kittttttan.info/py/pe26 """ def cycle(n): i = 1 if not n & 1: return cycle(n >> 1) if not n % 5: return cycle(n // 5) while 1: if not (10**i - 1) % n: return i i += 1 def pe26(d=1000): """ Find the value of d < 1000 for which 1/d contains the longest recurring cycle. """ m, l = 0, 0 for d in range(1, 1000): c = cycle(d) if c > m: m, l = d, c print(m, l) if __name__ == "__main__": pe26()