Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from functools import lru_cache
- from fractions import Fraction
- @lru_cache(maxsize=None)
- def calculate_fraction(n):
- if n == 0:
- return 0
- if n == 1:
- return 1
- else:
- return 1 + Fraction(1, 1 + continued_fraction(n - 1))
- is_more_digits = lambda l: len(str(l.numerator)) > len(str(l.denominator))
- def main():
- count = 0
- for i in range(2, 1003):
- if is_more_digits(calculate_fraction(i)):
- count += 1
- return count
- if __name__ == '__main__':
- main()
- ###################################################
- # CPU times: user 128 ms, sys: 0 ns, total: 128 ms
- # Wall time: 126 ms
- # Out[141]: 153
- ###################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement