Convergents of Eproblem 65
The square root of 2 can be written as an infinite continued fraction.
| √2 = 1 + |
1 |
| |
2 + |
1 |
| |
|
2 + |
1 |
| |
|
|
2 +< /td> |
1 |
| |
|
|
|
2 + ... |
The infinite continued fraction can be written,√2 = [1; (2)] and (2) indicates that 2 repeats ad infinitum. In a similar way,√23 = [4; (1,3,1,8)].
It turns out this sequence of the partial values of continued fractions for square roots provide the best rational approxi Mations. Let us consider the convergents for√2.
| 1 + |
1 |
= 17/12 |
| |
2 + |
1 |
|
| |
|
2 +< /td> |
1 |
& nbsp; |
| |
|
|
2 |
|
/table>
| 1 + |
1 |
= 41/29 |
| |
2 + |
1 |
| |
|
2 + |
1 |
|
| |
|
&nbs P; |
2 + |
1 |
|
| |
|
|
|
2 |
Hence the sequence of the first ten convergents for√2 are:
1, 3/2, 7/5, 17/12, 41/29, 99/70, 239/169, 577/408, 1393/985, 3363/2378, ...
What's most surprising are that the important mathematical constant,
e = [2; 1,2,1, 1,4,1, 1,6,1, ...,K, 1, ...].
The first ten terms in the sequence of convergents for e is:
2, 3, 8/3, 11/4, 19/7, 87/32, 106/39, 193/71, 1264/465, 1457/536, ...
The sum of digits in the numerator of the 10th convergent is 1+4+5+7=17.
Find the sum of digits in the numerator of the 100th convergent of the continued fraction for e.
Python code:
def func (result,i):
T=I*RESULT[1]+RESULT[0]
RESULT[0]=RESULT[1]
Result[1]=t
return result
def func1 (x):
if (x%3) ==0:
k=2* (X/3)
Else
K=1
Return K
n=100
RESULT=[1,FUNC1 (N)]
For I in Range (n-1,1,-1):
Result=func (RESULT,FUNC1 (i))
RESULT[0]+=2*RESULT[1]
TEMP=STR (int (result[0]))
Result=0
K=len (temp)
For I in Range (0,k):
Result+=int (Temp[i])
Print (Result)
Time: <1s
Euler program (python) problem