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/ ...
随机推荐
- Scala学习——简介
一.Scala简介 Scala 是 Scalable Language 的简写,是一门多范式的编程语言,设计初衷是实现可伸缩的语言并集成面向对象编程和函数式编程的各种特性. 二.Scala 环境搭建 ...
- NOIp 2020
游记 Day-1 我已经开始慌了. 不知道前路如何.不想回文化课.唯一一次机会,可是这几天却一直在颓,不颓就慌. 没心思写题,导致这几天看的题啥都不会.不知道考试当天又会出什么幺蛾子. 啊啊啊,烦. ...
- 第二十九篇 -- PY程序返回值问题
今天兴之所至,来写一写关于程序返回值的问题.普通的py程序就不用多说了,sys.exit(result),result就是你想返回的返回值啦.我们今天来讲讲用PyQt5写的带界面的程序如何设置返回值的 ...
- CentOS7下OpenLDAP部署
OpenLDAP作为开源的LDAP服务,可用于搭建统一认证平台,在很多企业内部应用比较广泛,本文将介绍在CentOS7下OpenLDAP的部署. 环境: CentOS 7.4 OpenLDAP 2.4 ...
- iOS实现常用地图坐标系转换(swift5)
// 桥接后,OC工程也可用 // HTMCoorTransform.swift // HTMapKit // // Created by LongMa on 2021/8/3. // import ...
- jdk的下载与安装教程
最近在学逆向,就是要反编译人家的java代码,在这之前要先安装环境,下面是下载和安装JDK的教程: 1.JDK下载地址: http://www.oracle.com/technetwork/java/ ...
- 资源适配【eg: values-sw600dp的命名和drawable-400dpi的命名】
通过getResources().getConfiguration().smallestScreenWidthDp获取即可 这篇文章讲了values-sw的适配: https://blog.csdn. ...
- 洛谷P2962题解
题面 看到 \(n \leq 35\) ,这是一个非常小的数据,但是 \(O(2^n)\) 的暴力跑不过去,所以考虑玄学做法 \(\text{Meet in Middle}\) .就是先做左边,然后做 ...
- 用 区间判断(if)来猜价格的高低
1 #include <stdio.h> 2 #include <stdlib.h> 3 int main() 4 { 5 int price = 150; 6 int gue ...
- 七夕特别篇|用Python绘画牛郎织女在鹊桥相见
大家好,我是辰哥~ 今天就是七夕节,首先提前祝福有伴侣的小伙伴,七夕快乐,没有伴侣的小伙伴,今天就会找到伴侣,(给看到这句话的你好运加持,哈哈哈). 作为会Python的我们必须做点好玩且有意义的东西 ...