Topic links
Now this is the subject of thousands grass mud horse passing through the heart
This is the same as the above question.
The subject is the sum of the numbers of the molecules in the 100th fractional expression of E.
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.
A pattern can be found above.
Wikipedia links: Even fractions with recursive formulas
So much is enough to solve the problem,
The above theorem 1, which is not used
e = [2; 1,2,1, 1,4,1, 1,6,1, ...,K, 1, ...].
a0=2
The following: 1,2,1,1,4,1,1,6,1, this pattern is obvious.
According to the rules above
Java code:
Packageproject61;ImportJava.math.BigInteger; Public classp65{voidrun () {BigInteger D=NewBigInteger ("1"); BigInteger N=NewBigInteger ("2"); for(intI= 2;i<=100;i++) {BigInteger temp=D; Longc = (i%3==0)? (I/3): 1; BigInteger BIGC=NewBigInteger (c+ ""); D=N; N=d.multiply (BIGC). Add (temp); } String tostr=n.tostring (); intresult = 0; for(intI=0;i<tostr.length (); i++) {result+ = integer.valueof (Tostr.charat (i) + ""); } System.out.println (Tostr+ "\nresult:" +result); } Public Static voidMain (string[] args) {LongStart =System.currenttimemillis (); NewP65 (). run (); LongEnd =System.currenttimemillis (); LongTime = end-start; System.out.println ("Run Time:" +time/1000+ "S" +time%1000+ "MS"); }}
If you just see this problem should feel that the number is not very large, but the molecule is: 6963524437876961749120273824619538346438023188214475670667
The number of the molecules and the numbers are: 272, to use the BigInteger type
Python program:
Import time as timedefmysum (num):returnsum (Map (INT,STR (num)))defGeta (i):ifi%3==0:return(I/3) Else: return1defrun (): H0= 1H1= 2 forIinchRange (2,101): A=Geta (i) H2= A * h1 +H0 H0=H1 H1=H2returnmysum (H2)if __name__=='__main__': Start=time.time () result=Run ()Print "running Time={0},result={1}". Format ((Time.time ()-start), result)
Python is written according to the above
Running time=0.0,result=272
Euler Project question 65th: Convergents of E