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的更多相关文章

  1. (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 ...

  2. (Problem 37)Truncatable primes

    The number 3797 has an interesting property. Being prime itself, it is possible to continuously remo ...

  3. (Problem 35)Circular primes

    The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, ...

  4. (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 ...

  5. (Problem 70)Totient permutation

    Euler's Totient function, φ(n) [sometimes called the phi function], is used to determine the number ...

  6. (Problem 53)Combinatoric selections

    There are exactly ten ways of selecting three from five, 12345: 123, 124, 125, 134, 135, 145, 234, 2 ...

  7. (Problem 49)Prime permutations

    The arithmetic sequence, 1487, 4817, 8147, in which each of the terms increases by 3330, is unusual ...

  8. (Problem 36)Double-base palindromes

    The decimal number, 585 = 10010010012(binary), is palindromic in both bases. Find the sum of all num ...

  9. (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, ...

随机推荐

  1. ORA-20000: ORU-10027: buffer overflow, limit of 10000 bytes

        要用dbms_output.put_line来输出语句,遇到以下错误: ERROR 位于第 1 行: ORA-20000: ORU-10027: buffer overflow, limit ...

  2. Http报文格式学习及Get和Post主要区别总结

    HTTP(HyperText Transport Protocol,超文本传送协议) http请求数据包的格式:头部(request line + header)+  数据(data) 头部和数据包体 ...

  3. HTTP使用BASIC认证的原理及实现方法 (转载)

    转自:http://blog.itpub.net/23071790/viewspace-709367 一.   BASIC认证概述 在HTTP协议进行通信的过程中,HTTP协议定义了基本认证过程以允许 ...

  4. 在windows下配置对github的操作--基本操作

    一.下载安装 git for widows软件 git for widows 是专门用来在windows下操作 github的软件,提供bash(命令行) 和 gui两种方式. 在bash下,其实就是 ...

  5. Scrambled Polygon(凸多边形,斜率)

    Scrambled Polygon Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 7805   Accepted: 3712 ...

  6. Objective-c 方法的调用

    在书写了类的声明和实现后,应用程序如何去调用它呢? 在Objective-c中,调用方法的简单格式如下: 1⃣   [实例  方法];    如: [person setAge:32];  其中 pe ...

  7. adb shell 命令

    adb 概述 SDK的Tools文件夹下包含着Android模拟器操作的重要命令adb,adb的全称为(Android Debug Bridge就是调试桥的作用.通过adb我们可以在Eclipse中方 ...

  8. DontDestroyOnLoad(Unity3D开发之五)

    Unity中我们从A场景切换到B场景的时候,A场景全部对象都会销毁,但有时候我不须要销毁某些东西. 比方一个简单的游戏的背景音乐,我不须要多次反复创建,多个场景播放这一个即可了.这个时候就须要用到Do ...

  9. 解決 centos中-bash: vim: command not found

    用centos 的主机的時候, 用 vim 时出现 -bash: vim: command not found. 只能使用 vi. 那么如何安裝 vim 呢? 输入 rpm -qa|grep vim ...

  10. gcc代码反汇编查看内存分布[2]: arm-linux-gcc

    arm-none-linux-gnueabi-gcc -v gcc version 4.4.1 (Sourcery G++ Lite 2010q1-202) 重点: 代码中的内存分配, 地址从低到高: ...