欧拉工程第64题:Odd period square roots
找循环位数是奇数的数有多少个
这个自己很难写出来,完全不能暴力
维基百科链接 维基百科上面说的很好,上面的算法实现就好了。
就是上面的
Java程序:
package project61; public class P64{ void run(){
int count = 0;
int m = 0;
int d = 1;
int a0 = 0;
int a = 0;
int period = 0;
for(int S = 2;S<10000;S++){
period = 0;
m = 0;
d = 1;
a0 = (int) (Math.sqrt(S));
if(a0*a0 == S) continue;
a = a0;
do{
m = d*a - m;
d = (S-m*m)/d;
a = (a0+m)/d;
period++;
}while(a!=2*a0);
if(period%2==1) count++;
}
System.out.println(count);
}
public static void main(String[] args){
long start = System.currentTimeMillis(); new P64().run(); long end = System.currentTimeMillis();
long time =end - start;
System.out.println("run time:"+ time/1000+"s"+time%1000+"ms");
}
}
Python程序
import time as time start = time.time() count = 0 for S in range(2,10000):
m = 0
d = 1
a0 = int(S**0.5)
if a0*a0 == S :continue
preiod = 0
a= a0
while a!=2*a0:
m = d*a - m
d = (S - m*m)/d
a = int((a0 + m)/d)
preiod+=1
if preiod%2==1:count +=1 end = time.time()
print "time={0} secs,count={1}".format((end-start),count)
上面两个程序几乎一样的
欧拉工程第64题:Odd period square roots的更多相关文章
- 欧拉工程第69题:Totient maximum
题目链接 欧拉函数φ(n)(有时也叫做phi函数)可以用来计算小于n 的数字中与n互质的数字的个数. 当n小于1,000,000时候,n/φ(n)最大值时候的n. 欧拉函数维基百科链接 这里的是p是n ...
- 欧拉工程第70题:Totient permutation
题目链接 和上面几题差不多的 Euler's Totient function, φ(n) [sometimes called the phi function]:小于等于n的数并且和n是互质的数的个 ...
- 欧拉工程第66题:Diophantine equation
题目链接 脑补知识:佩尔方差 上面说的貌似很明白,最小的i,对应最小的解 然而我理解成,一个循环的解了,然后就是搞不对,后来,仔细看+手工推导发现了问题.i从0开始变量,知道第一个满足等式的解就是最小 ...
- 欧拉工程第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 ...
- 欧拉工程第65题:Convergents of e
题目链接 现在做这个题目真是千万只草泥马在心中路过 这个与上面一题差不多 这个题目是求e的第100个分数表达式中分子的各位数之和 What is most surprising is that the ...
- 欧拉工程第56题:Powerful digit sum
题目链接 Java程序 package projecteuler51to60; import java.math.BigInteger; import java.util.Iterator; im ...
- 欧拉工程第55题:Lychrel numbers
package projecteuler51to60; import java.math.BigInteger; import java.util.Iterator; import java.util ...
- 欧拉工程第54题:Poker hands
package projecteuler51to60; import java.awt.peer.SystemTrayPeer; import java.io.BufferedReader; impo ...
- 欧拉工程第53题:Combinatoric selections
package projecteuler51to60; class p53{ void solve1(){ int count=0; int Max=1000000; int[][] table=ne ...
随机推荐
- Android开发面试题(一)
1.String和StringBuffer有什么本质区别? 本质区别:String字符串不可变,每次修改字符串必须要重新赋值(生成新的对象)才能修改:StringBuffer字符串可变,可以直接对字符 ...
- .NET研发人员面试题(二)
1.当使用new BB()创建BB的实例时,产生什么输出? public class AA { public AA() { PrintFields(); } public virtual void P ...
- How to add EDT relation table[AX2012]
setp 1. First create New Edit. setp 2.Create New Table First Table Name is NParentRel then drag and ...
- Jquery插件收集
移动端滚动条插件iScroll.js http://www.cnblogs.com/starof/p/5215845.html http://www.codeceo.com/article/35-jq ...
- C#不同页面之间通信的方法
以前做项目的时候经常头疼两个页面之间的交互(汗),这几天看的MVVM项目,忽然感觉好简单的!我自己写了个简单的demo 可以简单实现2个页面之间的交互,新人第一次发博客,不喜勿喷 代码很简单,注释我就 ...
- MySQL Online DDL 工具之pt-online-schema-change
MySQL DDL:DDL是一个令所有MySQL dDBA 诟病的一个功能,因为在MySQL中在对表进行dDDL时,会锁表,当表比较小比如小于1W行时,对前端影响较小,当时遇到千万级别的表,就会影响前 ...
- eclipse下mysql编程
mysql -uroot -p 密码 1:如果/usr/include/mysql路径下不存在头文件请: apt-get install libmysql++安装开发包 2:程序中添加头文件<m ...
- Java 线程池框架核心代码分析
前言 多线程编程中,为每个任务分配一个线程是不现实的,线程创建的开销和资源消耗都是很高的.线程池应运而生,成为我们管理线程的利器.Java 通过Executor接口,提供了一种标准的方法将任务的提交过 ...
- 【个人笔记】003-PHP基础-01-PHP快速入门-03-PHP环境搭建
003-PHP基础-01-PHP快速入门 03-PHP环境搭建 1.客户端(浏览器) IE FireFox CHROME Opera Safari 2.服务器 是运行网站的基本 是放置程序代码的地方 ...
- 计划:怎样理解水平集方法 ITK Level set V4 框架介绍
简易解释:在曲面中插入一个平面所形成的轮廓,即是该轮廓的水平集表示,可见,该轮廓的水平集表示有多个.对于图像分割,在图像力的驱动下曲面进行更新. 轮廓的数学表达有隐式和显式两种表达.用曲面演化代替Fr ...