题目: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?

方法一:

 1 #include<iostream>
2 using namespace std;
3 bool isPrime(long long num);
4 int main() {
5 int count = 1;//考虑到2为第一个素数
6 long long num = 3;
7 while(true) {
8 if(isPrime(num))
9 count++;
10 if(10001 == count){
11 break;
12 }
13 num++;
14 }
15 cout << num;
16 system("pause");
17 return 0;
18 }
19 bool isPrime(long long num){
20 int i=0;
21 for(i = 2; i*i <= num; i++){
22
23 if(num%i == 0)
24 return false;
25 }
26 return true;
27 }

方法二:

 1 #include<iostream>
2 using namespace std;
3 typedef unsigned int uint;
4 const uint N = 200000;
5 int main() {
6 uint *n = new uint[N];
7 uint count = 0;
8 for(uint i =0; i<N; i++) {
9 n[i]=i;
10 }
11 for(uint j = 2; j < N;j++) {
12 if(n[j] != 0){
13 count++;
14 cout << n[j] << endl;
15 if(10001 == count){
16 cout << n[j] << endl;
17 break;
18 }
19 for(uint k = j+1; k < N;k++){
20 if(n[k]!=0 && n[k] % j == 0)
21 n[k]=0;
22 }
23 }
24 }
25 delete [] n;
26 cout << num;
27 system("pause");
28 return 0;
29 }

ProjectEuler 007题的更多相关文章

  1. ProjectEuler 做题记录

    退役选手打发时间的PE计划 挂在这里主要是dalao们看到有什么想交流的东西可以私聊哦(站内信或邮箱吧)~~当然现在高三也不怎么能上网. 2017/8/11  595 :第一题QAQ 2017/8/1 ...

  2. ProjectEuler 005题

    题目: 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any ...

  3. ProjectEuler 009题

    题目: A Pythagorean triplet is a set of three natural numbers, a b c, for which, a2 + b2 = c2 For exam ...

  4. ProjectEuler 008题

    题目: The four adjacent digits in the 1000-digit number that have the greatest product are 9 9 8 9 = 5 ...

  5. ProjectEuler 006题

    题目: The sum of the squares of the first ten natural numbers is, 12 + 22 + ... + 102 = 385 The square ...

  6. ProjectEuler 004题

    1 #include<iostream> 2 using namespace std; 3 4 int main() { 5 bool isPalindromic (int num); 6 ...

  7. ProjectEuler 003题

    1 //题目:The prime factors of 13195 are 5, 7, 13 and 29. 2 //What is the largest prime factor of the n ...

  8. nim也玩一行流,nim版的list comprehension

    nim 是一门风格类似python的静态编译型语言,官方网站:http://nim-lang.org 如果你想折腾nim的编辑环境,可以用sublime text3 +插件nimlime,notepa ...

  9. ProjectEuler && Rosecode && Mathmash做题记录

    退役选手打发时间的PE计划 挂在这里主要是dalao们看到有什么想交流的东西可以私聊哦(站内信或邮箱吧) 2017/8/11  PE595 :第一题QAQ 2017/8/12  PE598 2017/ ...

随机推荐

  1. sql-4-函数

    常见函数 1.运算函数 select ABS(-8) -- 绝对值 select ceiling(9.4) -- 向上取整 select floor(9.4) -- 向下取整 select rand( ...

  2. springMVC-3-获取参数

    RequestMapping修饰类 源码: 根据源码可以知道,requestmapping既可以修饰方法也可以修饰类 @Target({ElementType.METHOD, ElementType. ...

  3. Scanner的基本语法及用法

    一.Scanner对象 基本语法中并没有实现程序和人的交互,但是Java给我们提供了一个这样的工具类,我们可以获取用户的输入.java.util.Scanner是Java5的新特征,我们可以通过Sca ...

  4. firewalld详解

    firewalld详解 注:为了便于查看,我把iptables和firewlld的使用总结文档放到了这个链接(下载),这个文档如果有新的内容和更正,我会及时更新. 有需要可以直接下载查看,应该比在博客 ...

  5. odoo14开发之脚本自动生成代码

    通过解析excel,自动生成odoo代码实现 一.首先做一个字段配置的excel模板 第二步.读取excel里面的模板,并写入到txt文件里 逻辑代码: # -*- coding: utf-8 -*- ...

  6. 第二十七篇 -- QTreeWidget总结

    前言 之前写过几篇关于TreeWidget的文章,不过不方便查阅,特此重新整合作为总结.不过关于QtDesigner画图,还是不重新写了,看 第一篇 就OK. 准备工作 1. 用QtDesigner画 ...

  7. 构建前端第13篇之---VUE的method:{}的括号未括到方法导致 _vm.linkProps is not a function

  8. 【Android】真机调试新姿势:无线连接

    由于工作需要,需要无线连接手机调试,特意百度了一下 在进行Android开发时,一般我们都是用usb线把手机和电脑连接起来进行调试工作.但如果你觉得这样不够酷的话,可以尝试一下无线连接,颇简单,GO! ...

  9. C# 事件与继承

    在窗体编程过程中,常常会封装一个基类,包含未来业务中常用的属性.方法.委托.事件等,但是事件作为一个特殊的委托,只能在声明类中调用,派生类都不可以调用,所以在基类中必须实现一个虚函数,实现事件的调用, ...

  10. Java基础——逻辑运算符、位运算符

    逻辑运算符.位运算符.三元运算符 逻辑运算符  public class Demon05 {     public static void main(String[] args) {          ...