题目链接

现在做这个题目真是千万只草泥马在心中路过

这个与上面一题差不多

这个题目是求e的第100个分数表达式中分子的各位数之和

What is most surprising is that the important mathematical constant,
e = [2; 1,2,1, 1,4,1, 1,6,1 , ... , 1,2k,1, ...].

The first ten terms in the sequence of convergents for e are:

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.

上面可以发现一个规律

维基百科链接:连分数,上面有递推公式

这么多就足够解题了,

上面的定理1,用不到的

e = [2; 1,2,1, 1,4,1, 1,6,1 , ... , 1,2k,1, ...].

a0=2

下面的:1,2,1,1,4,1,1,6,1,这个规律很明显

 

根据上面的规律

Java代码:

package project61;

import java.math.BigInteger;

public class P65{
void run(){
BigInteger d = new BigInteger("1");
BigInteger n = new BigInteger("2");
for(int i= 2;i<=100;i++){
BigInteger temp = d;
long c = (i%3==0)?2*(i/3):1;
BigInteger BigC = new BigInteger(c+"");
d = n;
n = d.multiply(BigC).add(temp);
}
String toStr = n.toString();
int result = 0;
for(int i=0;i<toStr.length();i++){
result += Integer.valueOf(toStr.charAt(i)+"");
}
System.out.println(toStr+"\nresult:"+result);
}
public static void main(String[] args){
long start = System.currentTimeMillis();
new P65().run();
long end = System.currentTimeMillis();
long time = end - start;
System.out.println("run time:"+time/1000+"s"+time%1000+"ms");
}
}

如果刚看到这一题的时候应该感觉这个数不是很大,然而分子是:6963524437876961749120273824619538346438023188214475670667

分子各位的数字和是:272,要用BigInteger类型

Python程序:

import time as time 

def mysum(num):
return sum(map(int,str(num))) def getA(i):
if i%3==0:
return 2*(i/3)
else:
return 1 def run():
h0 = 1
h1 = 2
for i in range(2,101):
a = getA(i)
h2 = a * h1 + h0
h0 = h1
h1 = h2
return mysum(h2) if __name__== '__main__':
start = time.time()
result = run()
print "running time={0},result={1}".format((time.time()-start),result)

Python是根据上面截图中的写的

running time=0.0,result=272

欧拉工程第65题:Convergents of e的更多相关文章

  1. 欧拉工程第69题:Totient maximum

    题目链接 欧拉函数φ(n)(有时也叫做phi函数)可以用来计算小于n 的数字中与n互质的数字的个数. 当n小于1,000,000时候,n/φ(n)最大值时候的n. 欧拉函数维基百科链接 这里的是p是n ...

  2. 欧拉工程第70题:Totient permutation

    题目链接 和上面几题差不多的 Euler's Totient function, φ(n) [sometimes called the phi function]:小于等于n的数并且和n是互质的数的个 ...

  3. 欧拉工程第66题:Diophantine equation

    题目链接 脑补知识:佩尔方差 上面说的貌似很明白,最小的i,对应最小的解 然而我理解成,一个循环的解了,然后就是搞不对,后来,仔细看+手工推导发现了问题.i从0开始变量,知道第一个满足等式的解就是最小 ...

  4. 欧拉工程第57题:Square root convergents

    题目链接 Java程序 package projecteuler51to60; import java.math.BigInteger; import java.util.Iterator; impo ...

  5. 欧拉工程第67题:Maximum path sum II

    By starting at the top of the triangle below and moving to adjacent numbers on the row below, the ma ...

  6. 欧拉工程第56题:Powerful digit sum

    题目链接   Java程序 package projecteuler51to60; import java.math.BigInteger; import java.util.Iterator; im ...

  7. 欧拉工程第55题:Lychrel numbers

    package projecteuler51to60; import java.math.BigInteger; import java.util.Iterator; import java.util ...

  8. 欧拉工程第54题:Poker hands

    package projecteuler51to60; import java.awt.peer.SystemTrayPeer; import java.io.BufferedReader; impo ...

  9. 欧拉工程第53题:Combinatoric selections

    package projecteuler51to60; class p53{ void solve1(){ int count=0; int Max=1000000; int[][] table=ne ...

随机推荐

  1. MATLAB light material lighting

    clf;[X,Y,Z]=sphere(40);colormap(jet)subplot(1,2,1),surf(X,Y,Z),axis off square,shading interplight(' ...

  2. 免费GIT托管

    http://www.gitcentral.com http://www.projectlocker.com http://gitfarm.appspot.com http://code.google ...

  3. PHPcms 摘要

    一  常量 /** *  主要定义了路径常量,项目中经常用到 **/ define('PHPCMS_PATH',dirname(__FILE__).DIRECTORY_SEPARATOR);// 项目 ...

  4. svn 清空

    SVN是目前用得比较多的而且很方便的版本管理体系. 在开发过程中遇到了这样的问题: 有时我们需要一个干净的code版本,没有 .svn 这些文件夹记录的版本传到服务器上使用. 这个时候自己一个个去删除 ...

  5. Repeat Header / Keep Header Visible in Tables in RS 2008

    You selected "Repeat header rows on each page" or "Keep header rows visible while scr ...

  6. CPU 时间片 分时 轮转调度

    时间片即CPU分配给各个程序的时间,每个线程被分配一个时间段,称作它的时间片,即该进程允许运行的时间,使各个程序从表面上看是同时进行的.如果在时间片结束时进程还在运行,则CPU将被剥夺并分配给另一个进 ...

  7. 【Go】为什么用go; Golang Erlang 前世今生

    给自己一条退路,再次比较Erlang和Golang 2014-6-28 陈叶皓 chenyehao@gmail.com 雨天的周末,适合码字的时节... 一年前我开始学习go语言的时候,如获至宝,既有 ...

  8. advance 模板 怎么生成module

    advance 模板 怎么生成module namespace写什么如果是前台呢就是 frontend\modules\modulename\Module@我叫红领巾 module id有什么用bak ...

  9. android实现可拖动按钮

    功能:在Android中实现可拖动按钮,同时实现按钮的点击功能 相关问题: 按钮拖动的界限限定. 按钮单击和拖动之间的冲突. 在界面未显示之前,获得View的高/宽. 问题描述: 如果不为按钮的拖动范 ...

  10. mysql left( right ) join使用on 与where 筛选的差异

    有这样的一个问题mysql查询使用mysql中left(right)join筛选条件在on与where查询出的数据是否有差异. 可能只看着两个关键字看不出任何的问题.那我们使用实际的例子来说到底有没有 ...