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

Problem7

阅读更多
package com.shui.mu.yao.io.algorithm;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 
 * @author shuimuqinghua77 @date 2011-11-3上午10:56:33
 * 
 */
/**
 * By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see
 * that the 6th prime is 13. What is the 10 001st prime number?
 */
public class Problem7 {
	private static List<Long> seed = new ArrayList<Long>();
	private static long count=7;
	static {
		seed.add(2l);
		seed.add(3l);
		seed.add(5l);

	}

	public static long findPrime(int index) throws Exception {
		while (seed.size()<index) {
			if(count==Long.MAX_VALUE)
			{
				throw new Exception("超过long类型最大值");
			}
			int flag=0;
			for(long l:seed){
				if(count%l==0)
				{
					flag=1;
					break;
				}
				
			}
			if(flag==0)
			seed.add(count);
			count++;
		}
		return seed.get(index-1);
	}
	public static void main(String[] args) throws Exception {
		long result=findPrime(10001);
		System.out.println(result);
		System.out.println(Arrays.toString(seed.toArray()));
	}
}
分享到:
评论

相关推荐

    numpy-numpy使用示例之problem7.zip

    numpy numpy_numpy使用示例之problem7

    week1_problem7:创世纪MBD提交的第1周第7个问题,由唯一ID 2005546 Gauri M Kulkarni

    而压缩包子文件的文件名称"week1_problem7-master"可能表明这是一个课程的第1周第7个问题的主目录,通常在编程课程中,这可能包含源代码、数据文件或其他相关资源。 然而,没有具体的文件内容,我无法提供详细的IT...

    爱立信CSR数据采集规范

    7. HLR redundancy problem 6 8. MRBT related problem 7 9. USSD related problem 7 10. Announcement problem 7 11. Echo canceller (ECP) problem 8 12. DTI problem 8 13. Group Switch problem 8 14. IN ...

    计算机网络第六版答案

    7. Ethernet LANs have transmission rates of 10 Mbps, 100 Mbps, 1 Gbps and 10 Gbps. 8. Today, Ethernet most commonly runs over twisted-pair copper wire. It also can run over fibers optic links. 9. ...

    Computer-Based.Problem.Solving.Process

    Chapter 7. Algorithmic Expression of a Hardware System Chapter 8. Using Computers to Solve Problems Part 3 Software Tools Supporting Program Execution Chapter 9. Computer Process Manipulation by ...

    Problem Solving with C++, 10th Global Edition

    Problem Solving with C++, Global Edition by Walter Savitch (author) (Author) Pages:1117 出版社: Pearson Education Limited; 10th edition edition (November 20, 2017) Language: English ISBN-10: ...

    Wicked Problem

    ### Wicked Problem与Wicked Environmental Problem #### 一、引言 "Wicked Problem"(棘手问题)这一概念最初由霍恩(Horst Rittel)和韦伯(Melvin Webber)于1973年提出,指的是那些复杂且难以解决的问题。这类...

    node-problem-detector-0.8.7.tar

    node-problem-detector 镜像包 v0.8.7 版本

    MCM 2012 problem A B C 论文

    MCM 2012年 problem A problem B problem C 枪手论文

    MySQL数据库考试试题.docx

    7. 删除表:DROP TABLE 语句(Problem 7) DROP TABLE 语句用于删除一个表,例如 DROP TABLE S; 8. 查找表结构:DESC 语句(Problem 8) DESC 语句用于显示表的结构信息,例如 DESC emp; 9. 获取最后一句 SELECT...

    Problem Arrangement zoj 3777

    Problem Arrangement zoj 3777

    problem

    标题 "problem" 提供的信息较少,但从描述中的 "NULL 博文链接:https://eric0000.iteye.com/blog/322311" 可以推测,这可能是一个关于解决某个问题或者技术讨论的博客文章链接。由于没有具体的博文内容,我们无法...

    算法设计taxi problem

    算法设计里关于taxi problem的C语言代码

    台大机器学习作业六1

    **Problem 7**:描述了最小二乘法(Least Squares Method)的解法,用于拟合线性模型,当误差平方和最小时找到最佳拟合线。 **Problem 8**:问题涉及到数据预处理,可能是在处理某些特定分布的数据,比如均匀分布,...

    Problem_C_Data.zip

    "Problem_C_Data.zip" 是一个压缩包文件,包含2020年美国数学建模竞赛(简称美赛)C题的题目及相应的原始数据。美赛是一项国际性的数学建模竞赛,每年吸引众多学生参与,旨在提升参赛者的数学、数据分析和解决实际...

    Problem 1002

    HDOJ Problem 1001 C++版

    master page search problem

    在这个特定的问题“master page search problem”中,我们可能遇到的是在使用Master Page时搜索功能出现的问题。ViewData是ASP.NET MVC框架中的一个特性,用于在控制器和视图之间传递数据,而JavaScript则是客户端...

    euler project.r.zip_R Euler project_project

    7. **Problem 7: 第10001个质数** - 知识点:质数判断,循环结构,计数。 - 解决方法:编写质数检测函数,从2开始迭代直到找到第10001个质数。 8. **Problem 8: 最大数字乘积** - 知识点:字符串处理,数组操作...

    machine problem

    在操作系统课程中,"机器问题"(Machine Problem)通常指的是与计算机硬件、系统架构以及操作系统内核相关的复杂问题。这些问题涉及到资源管理、并发控制、进程调度、内存分配等多个核心概念,是理解操作系统工作...

    gre subject

    **Problem Statement:** If \(3x + 7y\) is divisible by 11, which of the following must also be divisible by 11? - **Concepts Involved:** Number theory, divisibility. - **Solution Approach:** Use the ...

Global site tag (gtag.js) - Google Analytics