Project Euler 57
Project Euler 57
题目
Square root convergents
It is possible to show that the square root of two can be expressed
as an infinite continued fraction.
The next three expansions are
In the first one-thousand expansions, how many fractions contain a numerator with more digits than the denominator?
解决方案
观察上面的连分数,将其写成一个序列
本代码使用的是 fractions
库中的 Fraction
类,它用于维护一个分数的类型。
代码
1 | from fractions import Fraction |