题意:求1到n中所有数的倒数中循环小数循环体最长的数

解法:如果一个数的质因子只有2和5,那么这个数的倒数一定不是一个循环小数。如果一个数含有质因子2或5,那么它的循环体和去掉质因子2和5之后的数的循环体是一样长的,如3和6。对于一个质因子没有2和5的数,能被几个9组成的数整除它的循环体就有多长,如1 / 7 = 0.(142857),999999 / 7 = 142857。

对于这个例子我做了简单的证明:

因为1 / 7 = 0.(142857),所以1000000 / 7 = 142857.(142857) = 142857 + 0.(142857) = 142857 + 1 / 7

所以999999 / 7  = 142857

代码:

循环体比较长……用了Java大数

package pe0026;

import java.math.*;

public class main
{
public static void main(String[] args)
{
int maxn = 0, pos = 0;
for(int i = 2; i <= 1000; i++)
{
if(i % 2 == 0 || i % 5 == 0)
continue;
BigInteger x = BigInteger.ZERO;
int cnt = 1;
while(true)
{
x = x.multiply(BigInteger.valueOf(10)).add(BigInteger.valueOf(9));
cnt++;
if(x.mod(BigInteger.valueOf(i)) == BigInteger.ZERO)
{
if(maxn < cnt)
{
maxn = cnt;
pos = i;
}
break;
}
}
}
System.out.println(pos);
}
}

  

Project Euler 26 Reciprocal cycles的更多相关文章

  1. Project Euler 26 Reciprocal cycles( 分数循环节 )

    题意: 单位分数指分子为1的分数.分母为2至10的单位分数的十进制表示如下所示: 1/2 =  0.5 1/3 =  0.(3) 1/4 =  0.25 1/5 =  0.2 1/6 =  0.1(6 ...

  2. project euler 26:Reciprocal cycles

    A unit fraction contains 1 in the numerator. The decimal representation of the unit fractions with d ...

  3. Project Euler Problem 26-Reciprocal cycles

    看样子,51nod 1035 最长的循环节 这道题应该是从pe搬过去的. 详解见论文的(二)那部分:http://web.math.sinica.edu.tw/math_media/d253/2531 ...

  4. Python练习题 044:Project Euler 016:乘方结果各个数值之和

    本题来自 Project Euler 第16题:https://projecteuler.net/problem=16 ''' Project Euler 16: Power digit sum 2* ...

  5. Python练习题 039:Project Euler 011:网格中4个数字的最大乘积

    本题来自 Project Euler 第11题:https://projecteuler.net/problem=11 # Project Euler: Problem 10: Largest pro ...

  6. [project euler] program 4

    上一次接触 project euler 还是2011年的事情,做了前三道题,后来被第四题卡住了,前面几题的代码也没有保留下来. 今天试着暴力破解了一下,代码如下: (我大概是第 172,719 个解出 ...

  7. Python练习题 029:Project Euler 001:3和5的倍数

    开始做 Project Euler 的练习题.网站上总共有565题,真是个大题库啊! # Project Euler, Problem 1: Multiples of 3 and 5 # If we ...

  8. Project Euler 9

    题意:三个正整数a + b + c = 1000,a*a + b*b = c*c.求a*b*c. 解法:可以暴力枚举,但是也有数学方法. 首先,a,b,c中肯定有至少一个为偶数,否则和不可能为以上两个 ...

  9. Project Euler 44: Find the smallest pair of pentagonal numbers whose sum and difference is pentagonal.

    In Problem 42 we dealt with triangular problems, in Problem 44 of Project Euler we deal with pentago ...

随机推荐

  1. NSInvocation的使用(转)

    转载自:http://www.cnblogs.com/pengyingh/articles/2359199.html http://blog.iosxcode4.com/?p=125 在 iOS中可以 ...

  2. netty sample

    http://netty.io/wiki/ https://github.com/netty/netty/tree/master/example/src/main/java/io/netty/exam ...

  3. 使用自定义任务审批字段创建 SharePoint 顺序工作流

    http://msdn.microsoft.com/zh-cn/library/hh824675(v=office.14).aspx#odc_sp14_ta_CreatingSPSeqWorkflow ...

  4. ParentChildTest.java

    public class ParentChildTest { public static void main(String[] args) { Parent parent=new Parent(); ...

  5. SCRUM,一个采用迭代,增量方法来优化可预见控制风险

    Scrum是一个用于开发和维持复杂产品的框架,是一个增量的,迭代的开发过程.在这个框架中,整个开发过程是由若干个短的迭代周期组成,一个短的迭代周期称为一个Sprint,每个Sprint的建议长度是2到 ...

  6. ExtJS4.2学习(12)基于表格的右键菜单(转)

    鸣谢:http://www.shuyangyang.com.cn/jishuliangongfang/qianduanjishu/2013-11-24/181.html --------------- ...

  7. COUNT(*)与COUNT(列名)的区别(转)

    COUNT(*)与COUNT(列名)的区别       以前一直没有留意到COUNT(*)与COUNT(列名)的区别,昨天晚上无意中看到数据库系统工程师教程里面的一句话."如果null参与聚 ...

  8. 使用Redis构建简单的ORM

    Reids相关的资料引用 http://www.tuicool.com/articles/bURJRj [Reids各种数据类型的应用场景] https://github.com/antirez/re ...

  9. 漫话C++0x(五)—- thread, mutex, condition_variable

    熟悉C++98的朋友,应该都知道,在C++98中没有thread, mutex, condition_variable这些与concurrency相关的特性支持,如果需要写多线程相关程序,都要借助于不 ...

  10. [java线段树]2015上海邀请赛 D Doom

    题意:n个数 m个询问 每个询问[l, r]的和, 再把[l, r]之间所有的数变为平方(模为9223372034707292160LL) 很明显的线段树 看到这个模(LLONG_MAX为922337 ...