题目链接

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

这个与上面一题差不多

这个题目是求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. 如何在Mac下使用TF/SD 卡制作Exynos 4412 u-boot启动盘

    /** ****************************************************************************** * @author    Maox ...

  2. aspx利用cookie值来停止silverlight中的计时器

    一.silverlight与silverlight中可以利用委托(delegate)来刷新frame.Refresh() 1.在子类中定义委托捕捉关闭事件按钮 public delegate void ...

  3. 初步了解SequoiaDB数据库

    随着企业中日益复杂与多变的需求,以及迅速扩展带来的海量数据的业务,IT部门需要将越来越多的信息提供给用户,同时在现今的全球经济背景环境下,IT部 门还需要在提供高效服务的同时,降低其设备与程序维护成本 ...

  4. centos系统下安装使用composer教程

    Composer 是 PHP 的一个依赖管理工具.它允许你申明项目所依赖的代码库,它会在你的项目中为你安装他们.Composer 不是一个包管理器.是的,它涉及 "packages" ...

  5. 服务管理,Dll查看

    //枚举系统进程 VOID CManageProcessDlg::ShowProcess() {           m_ListProcess.DeleteAllItems();      HAND ...

  6. SQL 查询分析器操作(修改、添加、删除)表及字段等

    一.库操作1..创建数据库命令:create database <数据库名>例如:建立一个名为xhkdb的数据库mysql> create database xhkdb; 2.显示所 ...

  7. 使用Sass优雅并高效的实现CSS中的垂直水平居中(附带Flex布局,CSS3+SASS完美版)

    实现css水平垂直居中的方法有很多,在这里我简单的说下四种比较常用的方法: 1.使用CSS3中的Flex布局 对于flex,我们要了解的是它是一个display的属性,而且必须要给他的父元素设置fle ...

  8. SQLserver利用系统时间生成“2015-11-30 00:00:00.000”类型的时间

    select getdate() ---当前时间:2015-12-18 10:20:24.097 -------------------建立测试表 Create Table #Test ( ID IN ...

  9. [Android Training视频系列] 8.1 Controlling Your App’s Volume and Playback

    主要内容:1 鉴别使用的是哪个音频流2 使用物理音量键控制应用程序的音量 3 使用物理播放控制键来控制应用程序的音频播放 视频讲解:http://www.eyeandroid.com/thread-1 ...

  10. 微软职位内部推荐-SDE2 (Windows driver)

    微软近期Open的职位: SDE2 (Windows driver) Job title: Software Development Engineer 2 Location: Shanghai, Ch ...