This commit is contained in:
2014-05-31 22:03:30 +04:00
parent 8d2c079900
commit 1c1c6fe543
871 changed files with 50851 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
/* Check cf5-opt.vim defs.
VIM: let g:lcppflags="-std=c++11 -O2 -pthread"
VIM: let g:wcppflags="/O2 /EHsc /DWIN32"
*/
#include <iostream>
#include <vector>
/*
Summation of primes
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.
Solution:
142913828922
*/
typedef std::vector<long long> pt;
pt p;
bool isPrime( long long n )
{
long h = (long long)sqrt(double(n));
for ( pt::iterator i = p.begin(), ie = p.end();
i!=ie && *i<=h;
++i )
if ( !(n%*i) )
return false;
return true;
}
int main ( void )
{
const long long n = 2000000;
long long s = 0;
for ( long long i = 2; i < n; ++ i )
if ( isPrime( i ) )
{
p.push_back( i );
s+=i;
}
std::cout << s << std::endl;
return 0;
}