ProjectEuler 007题
题目: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题的更多相关文章
- ProjectEuler 做题记录
退役选手打发时间的PE计划 挂在这里主要是dalao们看到有什么想交流的东西可以私聊哦(站内信或邮箱吧)~~当然现在高三也不怎么能上网. 2017/8/11 595 :第一题QAQ 2017/8/1 ...
- ProjectEuler 005题
题目: 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any ...
- ProjectEuler 009题
题目: A Pythagorean triplet is a set of three natural numbers, a b c, for which, a2 + b2 = c2 For exam ...
- ProjectEuler 008题
题目: The four adjacent digits in the 1000-digit number that have the greatest product are 9 9 8 9 = 5 ...
- ProjectEuler 006题
题目: The sum of the squares of the first ten natural numbers is, 12 + 22 + ... + 102 = 385 The square ...
- ProjectEuler 004题
1 #include<iostream> 2 using namespace std; 3 4 int main() { 5 bool isPalindromic (int num); 6 ...
- ProjectEuler 003题
1 //题目:The prime factors of 13195 are 5, 7, 13 and 29. 2 //What is the largest prime factor of the n ...
- nim也玩一行流,nim版的list comprehension
nim 是一门风格类似python的静态编译型语言,官方网站:http://nim-lang.org 如果你想折腾nim的编辑环境,可以用sublime text3 +插件nimlime,notepa ...
- ProjectEuler && Rosecode && Mathmash做题记录
退役选手打发时间的PE计划 挂在这里主要是dalao们看到有什么想交流的东西可以私聊哦(站内信或邮箱吧) 2017/8/11 PE595 :第一题QAQ 2017/8/12 PE598 2017/ ...
随机推荐
- 【LeetCode】66. 加一
66. 加一 知识点:数组: 题目描述 给定一个由 整数 组成的 非空 数组所表示的非负整数,在该数的基础上加一. 最高位数字存放在数组的首位, 数组中每个元素只存储单个数字. 你可以假设除了整数 0 ...
- React组件三大属性之 props
React组件三大属性之 props 理解1) 每个组件对象都会有props(properties的简写)属性2) 组件标签的所有属性都保存在props中 作用1) 通过标签属性从组件外向组件内传递变 ...
- Linux从入门到进阶全集——【第十五集:安装apache服务器】
1,查看是否安装了httpd软件包以及其依赖:rpm -qa httpd(rpm -qa | grep httpd),如果没有输出任何信息,表示你没有安装httpd软件包,如果有输出一般是已经安装了: ...
- 10、Java——内部类
1.类中定义类 (1)当一类中的成员,作为另外一种事物的时候,这个成员就可以定义为内部类. (2)分类:①成员内部类 ②静态内部类 ③私有内部类 ④局部内部类 ⑤匿名内部类 ⑥Lambda表达式 ...
- 关于java.lang.IllegalMonitorStateException异常说明(四)
1.异常原因及解释 首先你要了解这个异常为什么会抛出,这个异常会在三种情况下抛出:1>当前线程不含有当前对象的锁资源的时候,调用obj.wait()方法;2>当前线程不含有当前对象的锁资源 ...
- 第二十七篇 -- QTreeWidget总结
前言 之前写过几篇关于TreeWidget的文章,不过不方便查阅,特此重新整合作为总结.不过关于QtDesigner画图,还是不重新写了,看 第一篇 就OK. 准备工作 1. 用QtDesigner画 ...
- Python基础之获取路径与切换路径
一直以为我写了关于路径有关的博客,看了一圈才发现没写,那么现在就来整理下. 一.获取当前路径 os.getcwd() 二.获取当前文件路径:(__file__是当前执行文件) os.path.absp ...
- LUSE: 无监督数据预训练短文本编码模型
LUSE: 无监督数据预训练短文本编码模型 1 前言 本博文本应写之前立的Flag:基于加密技术编译一个自己的Python解释器,经过半个多月尝试已经成功,但考虑到安全性问题就不公开了,有兴趣的朋友私 ...
- Python: 解析crontab正则,增加+操作
以下是使用Python解析crontab时间格式的一个类, 同时minute和hour支持了 + 的操作. 记录一下备忘. 其中的line参数是字符串分拆后的格式, 包含了 "week&qu ...
- Podman 快速入门
今天在某云上新购一台云服务器,发现已经有了 CentOS8.2 官方镜像可选,出于对新鲜事物的好奇,我决定开始采用 CentOS8.2,即使我还没有为它的新特性做好准备. 我的应用主要以单机版容器为主 ...