`
水木清华77
  • 浏览: 37254 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

Problem26

阅读更多
A unit fraction contains 1 in the numerator. The decimal representation of the unit fractions with denominators 2 to 10 are given:

1/2 = 0.5
1/3 = 0.(3)
1/4 = 0.25
1/5 = 0.2
1/6 = 0.1(6)
1/7 = 0.(142857)
1/8 = 0.125
1/9 = 0.(1)
1/10 = 0.1
Where 0.1(6) means 0.166666..., and has a 1-digit recurring cycle. It can be seen that 1/7 has a 6-digit recurring cycle.

Find the value of d  1000 for which 1/d contains the longest recurring cycle in its decimal fraction part.
package euler;

import java.util.HashSet;
import java.util.Set;

/**
 * 
 * @author hongfa.yy
 * @version 2013-2-6 下午4:48:51
 */
public class Problem26 {
	public static void main(String[] args) {
		int max = 0;
		int max_d=0;
		for (int i = 1; i < 1000; i++) {
			int count = count(i);
			if (count > max){
				max_d=i;
				max = count;
			}
				
		}
		System.out.println(max_d);
	}

	private final static int decimalism = 10;

	private static int count(int denominator) {
		Set<Integer> set = new HashSet<>();
		int mode = 1 * decimalism % denominator;
		while (mode != 0) {
			if (!set.contains(mode))
				set.add(mode);
			else
				return set.size();
			mode = mode * decimalism % denominator;
		}

		return 0;
	}
}
分享到:
评论

相关推荐

    计算机网络第六版答案

    26. a) Virus Requires some form of human interaction to spread. Classic example: E-mail viruses. b) Worms No user replication needed. Worm in infected host scans IP addresses and port numbers, ...

    MySQL数据库考试试题.docx

    MySQL数据库考试试题 以下是根据提供的文件信息生成的相关知识点: ...26. 创建表语句:CREATE TABLE 语句(Problem 26) CREATE TABLE 语句用于创建一个新的表,例如 CREATE TABLE SC (S# CHAR, ...);

    python3-libs-3.6.8-41.el8.x86_64.rpm

    官方离线安装包,亲测可用

    Ulam’s problem without feedback—in advance.pdf

    ### Ulam's Problem:在没有反馈的情况下搜索与说谎者博弈 #### 一、问题背景与定义 Ulam的问题起源于斯坦尼斯拉夫·乌拉姆(Stanislaw Ulam)提出的一个智力游戏,该问题涉及到如何在面对可能的谎言回答时确定一...

    MATLAB 优化问题 26个测试函数

    在这个压缩包中,包含了26个测试函数,这些函数是为评估和比较优化算法性能而设计的。MATLAB用户经常使用这样的测试集来验证自定义优化算法的有效性,或者对比内置优化工具箱的功能。 "benchmark_func.m"很可能是主...

    delphi2010皮肤控件-VCLSkinv5.30FS

    Delphi VCLSkin 5.30 ... VCLSkin is a component to create skinnable user interface for Delphi/C++Builder application, It is easy to use, just put one component on mainform, ...* fix caption paint problem...

    leetcode不会-ProblemSolving-LeetCode:问题解决-LeetCode

    leetcode 不会问题解决-LeetCode 破解代码面试: ...26 for i in range ( len ( astr )): index = ord ( astr [ i ]) - ord ( 'a' ) if arr [ index ] == 1 : return False else : arr [ index ] += 1 return T

    算法导论3英文kindle

    26; 41; 58i, a sorting algorithm returns as output the sequence h26; 31; 41; 41; 58; 59i. Such an input sequence is called an instance of the sorting problem. In general, an instance of a problem ...

    ACM学习资料汇总,ACMer要试试哦!

    - [题目26](http://acm.pku.edu.cn/JudgeOnline/problem?id=2449) —— 可重复K最短路,A*搜索。 - [题目27](http://acm.pku.edu.cn/JudgeOnline/problem?id=1190) —— 深度优先搜索剪枝。 - [题目28]...

    Interpersonal problem solving and children's social competence: Are current measures valid?

    Volume 26, January 1989 INTERPERSONAL PROBLEM SOLVING AND CHILDREN’S SOCIAL COMPETENCE: ARE CURRENT MEASURES VALID?’ C . JULIUS MEISEL University of Delaware Ninety-four first- and second-...

    Ga.rar_JAVA GA TS_More Than Time_ga tsp vehicle_tsp

    monographs are devoted to the subject [34, 26]. Since the TSP is NP-hard, polynomial-time approximation algorithms are usually studied. However, usually the approaches to the study of vehicle routing ...

    Delphi2010皮肤控件AlphaControls6.21FS

    26.06.2008 AlphaControls v5.50 stable released * TsNotebook component was completely changed * Many small improvements 18.06.2008 AlphaControls v5.49 stable released * Solved problem of MDI ...

    CA-100CUSB充电线改装为移动电源

    1.00.2160 (October 26, 2004) Added option to prevent modem control signals following legacy port behaviour at startup. 1.00.2159 (October 15, 2004) Fixed delay on disconnect under WinXP. 1.00....

    Hadoop in Practice(2012)

    2012 | ISBN-10: 1617290238 | PDF, EPUB | 536 pages | 26 + 37 MB Hadoop in Practice collects 85 Hadoop examples and presents them in a problem/solution format. Each technique addresses a specific ...

    Aversiveness of teacher-chosen interventions and student problem characteristics: Is there a relationship?

    Aversiveness of teacher-chosen interventions and student problem characteristics: Is there a relationship? Fragile X Syndrome 389 WECHSLER, D. (1958). The measurement and appraisal of adult ...

    CCNA V26 题目

    A Layer 1 problem exists**:这表明可能存在的问题是物理层的问题,如连接线缆、端口故障等。 - **B. The bandwidth is set too low**:带宽设置得过低通常不会导致接口状态显示为down。 - **C. A protocol ...

    leetcode装最多水-problem-solving:解决问题

    26 6 23 关联 7 27 关联 8 112 关联 9 104 10 167 关联 11 21 12 121 13 53 14 35 15 122 16 110 17 257 18 637 19 242 20 252 中等的 问题 力码# 解决方案 1 2 关联 2 3 3 12 关联 4 34 5 92 关联 6 1249 7 142 8 ...

    tsp问题matlab代码步骤-Travelling-Salesman-Problem:使用约束生成技术解决旅行商问题

    tsp问题matlab代码步骤...US26.dat:在美国随机选择的26个州首府的坐标 tourmap_48.png:48个城市游览的地块 tourmap_26.png:26个城市游览的地块 US48TourPlot.m:Matlab代码以绘制使用Mosel代码生成的48个城市游览 US

Global site tag (gtag.js) - Google Analytics