(Problem 10)Summation of primes
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
Find the sum of all the primes below two million.
#include<stdio.h>
#include<math.h>
#include<stdbool.h> #define N 2000000 bool prim(int n)
{
int i;
for(i=; i*i<=n; i++)
{
if(n%i==)
return false;
}
return true;
} int main()
{
int i;
long long sum=;
for(i=; i<=N; i=i+)
{
if(prim(i))
{
sum+=i;
}
}
printf("%lld\n",sum); return ;
}
|
Answer:
|
142913828922 |
(Problem 10)Summation of primes的更多相关文章
- (Problem 47)Distinct primes factors
The first two consecutive numbers to have two distinct prime factors are: 14 = 2 7 15 = 3 5 The fi ...
- (Problem 37)Truncatable primes
The number 3797 has an interesting property. Being prime itself, it is possible to continuously remo ...
- (Problem 35)Circular primes
The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, ...
- (Problem 42)Coded triangle numbers
The nth term of the sequence of triangle numbers is given by, tn = ½n(n+1); so the first ten triangl ...
- (Problem 70)Totient permutation
Euler's Totient function, φ(n) [sometimes called the phi function], is used to determine the number ...
- (Problem 53)Combinatoric selections
There are exactly ten ways of selecting three from five, 12345: 123, 124, 125, 134, 135, 145, 234, 2 ...
- (Problem 49)Prime permutations
The arithmetic sequence, 1487, 4817, 8147, in which each of the terms increases by 3330, is unusual ...
- (Problem 36)Double-base palindromes
The decimal number, 585 = 10010010012(binary), is palindromic in both bases. Find the sum of all num ...
- (Problem 29)Distinct powers
Consider all integer combinations ofabfor 2a5 and 2b5: 22=4, 23=8, 24=16, 25=32 32=9, 33=27, 34=81, ...
随机推荐
- linux 命令大全
工作了一段时间,开始整理资料,好记性不如烂笔头啊. linux命令大全下载路径: 1.http://www.pc6.com/SoftView/SoftView_28912.html 2.http:// ...
- Webx pull service
1.概述 pull service的功能是将对象置入模板中.被pull service放到模板中的对象,不需要应用程序的干预即可直接使用.如果模板没有用到某个对象,则不会产生创建该对象的开销.看起来, ...
- libcprops
Install Howto Download the latest epel-release rpm from http://dl.fedoraproject.org/pub/epel/6/x86_6 ...
- jQuery File Upload
jQuery File Upload介绍.............................................. 2 实现基本原理......................... ...
- PCB的整个加工流程
1 MI:制作生产流程卡,指导产线如何去生产出所需要的pcb.2 内层:PCB,除了最便宜的单层板,简单的双层板,有时候需要使用4层 6层 8层,以实现复杂的连 接关系和高密度,再就是减少干扰或者降低 ...
- MaxSubArray 最大子数列和
public int maxSubArray(int[] A) { int newsum=A[0]; int max=A[0]; for(int i=1;i<A.length;i++){ new ...
- PHP面试题汇总参考
PHP面试题汇总 这是一份比较全面的PHP面试题.对准备去新公司应聘PHP职位的开发者应该有帮助.或者说,对招聘PHP开发人员的企业也有些帮助,不过就不要原样打印出来考了,稍微改一改. 简述题(50分 ...
- C#中字符串的处理,对象的引用及继承(Tenth day)
又进入到了新的一周,现在到总结的时间了,继续为大家总结一下今天在云和学院所学的知识. 理论: StringBuilder 和 String 的区别 String 在进行运算时(如赋值.拼接等)会 ...
- 自定义cell相关注意事项
1.拖线成功后,如果又在.h文件或者.m文件里面删除了对应的属性或者方法.一定要在xib文件中,删除关联.方法是:右键点击一下对应的UI控件,把多余的关联叉掉就行了. 不然容易崩溃.
- BZOJ 1691: [Usaco2007 Dec]挑剔的美食家( 平衡树 )
按鲜嫩程度排个序, 从大到小处理, 用平衡树维护价值 ---------------------------------------------------------------------- #i ...