`
水木清华77
  • 浏览: 36249 次
  • 性别: 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

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

    0-1-knapsack-problem-master (26)c.zip

    在本项目"0-1-knapsack-problem-master (26)c.zip"中,我们将会看到这个问题的C语言实现。 首先,我们需要理解0-1背包问题的基本概念。在这个问题中,我们有n个物品,每个物品i有一个重量wi和一个价值vi。背包有一...

    0-1-knapsack-problem-master (26).zip

    0-1 背包问题(0-1 Knapsack Problem)是计算机科学中的一个经典优化问题,尤其在算法设计和分析领域具有重要的研究价值。它属于组合优化问题,经常出现在背包类问题、资源分配、投资策略等场景。在这个问题中,我们...

    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 ...

    docker-ce-26.1.0使用yum安装包

    说明:在最小化CentOS Linux release 7.6.1810 中制作yum源,docker-ce是centos 7系统x86架构rpm包。 使用: 1、上传文件到/data/docker-ce解压,或者任意目录后修改docker-ce-26.1.0.repo 中baseurl路径。...

    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 ...

Global site tag (gtag.js) - Google Analytics