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/ ...
随机推荐
- 自动执行文件夹中的py文件
写一个函数,接收一个地址,执行其中的py文件,包括子文件.path.endswith('.py') 判断以'.py'结尾,是什么类型的文件.os.system('python %s'%path) 模拟 ...
- 【LeetCode】930. 和相同的二元子数组
930. 和相同的二元子数组 知识点:数组:前缀和: 题目描述 给你一个二元数组 nums ,和一个整数 goal ,请你统计并返回有多少个和为 goal 的 非空 子数组. 子数组 是数组的一段连续 ...
- Appium - adb monkey参数(三)
monkey 参数 1.常规类参数 A.帮助类参数 monkey -h B.日志级别 $ adb shell monkey -v <event-count> . 2.事件类参数 A .执 ...
- CSS居中对齐终极指南
本文首发于我的公众号:前端新世界 欢迎关注 本文将讨论可用于居中对齐元素的6种CSS技术(按照最佳实践排序),以及每一种技术最适合应用的场景.这里,居中对齐指的是将元素放置在其父元素的水平和垂直中心. ...
- OpenFaaS实战之二:函数入门
欢迎访问我的GitHub https://github.com/zq2599/blog_demos 内容:所有原创文章分类汇总及配套源码,涉及Java.Docker.Kubernetes.DevOPS ...
- LC-322. 零钱兑换
322. 零钱兑换 给你一个整数数组 coins ,表示不同面额的硬币:以及一个整数 amount ,表示总金额. 计算并返回可以凑成总金额所需的 最少的硬币个数 .如果没有任何一种硬币组合能组成总金 ...
- NOI2021游记
NOI2021游记 前言 写于 2021.7.28,成绩榜刚出后几个小时.总分 345 拿到银牌 183 名. 我的高中 OI 生活在这里画上句号.结局对我而言虽然不够完美,但是无论怎样都是我人生道路 ...
- ThreadLocal(十一)
一.ThreadLocal源码剖析 ThreadLocal源码剖析 ThreadLocal其实比较简单,因为类里就三个public方法:set(T value).get().remove().先剖析源 ...
- Mysql命令语句
常用的管理命令 SHOW DATABASES; //显示当前服务器下所有的数据库 USE 数据库名称; //进入指定的数据 show tables; ...
- springboot整合javafx
原文(原码)参考地址: https://github.com/roskenet/springboot-javafx-support https://github.com/spartajet/javaf ...