博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Project Euler Problem 10: Summation of primes
阅读量:6902 次
发布时间:2019-06-27

本文共 808 字,大约阅读时间需要 2 分钟。

Problem 10

The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.

Find the sum of all the primes below two million.

C++:

#include 
#include
#include
using namespace std;const int MAXN = 2000000;bool sieveflag[MAXN+1];void esieve(int n){ // 初始化 memset(sieveflag, true, sizeof(sieveflag)); sieveflag[0] = false; sieveflag[1] = false; for(int i=4; i<=n; i+=2) sieveflag[i] = false; // 筛选 int max = sqrt(n); for(int i=3; i<=max; i+=2) { if(sieveflag[i]) { for(int j=i+i; j<=n; j+=i) sieveflag[j] = false; } }}int main(){ esieve(MAXN); int n; while(cin >> n && n<=MAXN) { long sum = 2; for(int i=3; i
参考链接:

转载于:https://www.cnblogs.com/tigerisland/p/7564030.html

你可能感兴趣的文章
[学习笔记]博弈论
查看>>
python基础:搜索路径
查看>>
python os sys模块(二)
查看>>
一次linux启动故障记录
查看>>
linux 3.10内核 xfs的一次io异常导致的hung crash
查看>>
Castle ActiveRecord学习笔记(转)
查看>>
change textblock background color when text equal to referenceValue
查看>>
springboot+mybatis环境的坑和sql语句简化技巧
查看>>
如何用oracle从身份证信息中提取出生日期?
查看>>
Keil C编译器的变量存储分配
查看>>
非常不错的js 屏蔽类加验证类
查看>>
Innodb间隙锁,细节讲解(转)
查看>>
Apache安装
查看>>
C语言练习题库----数组
查看>>
算法的时间复杂度详解
查看>>
制作3D旋转视频展示区
查看>>
Spring.Net初认识——竹子整理
查看>>
win7 下 vmware 虚拟机开后 w字母键失效不能用 解决方案:
查看>>
[网络流24题-8]汽车加油行驶问题
查看>>
Vim使用技巧(2) -- 插入模式技巧 【持续更新】
查看>>