Last active
August 29, 2015 14:15
-
-
Save takanakahiko/c210eff0a5372e56d8d8 to your computer and use it in GitHub Desktop.
エラトステネスのふるい(競技プログラミング2013 2.4)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
using namespace std; | |
vector<bool> sieve(int N){ | |
vector<bool> ps(N+1, true); | |
ps[0] = ps[1] = false; | |
for(int i = 2; i < N; ++i){ | |
if(!ps[i]) | |
continue; | |
for(int j = i+i; j < N; j += i) | |
ps[j]= false; | |
} | |
return ps; | |
} | |
int main(void){ | |
vector<bool> primes = sieve(20000000); | |
for(int a, d, n; cin >> a >> d >> n,(a || d || n);){ | |
for(int x = a; n; x += d){ | |
if(!primes[x]) | |
continue; | |
if(!--n){ | |
cout << x << endl; | |
break; | |
} | |
} | |
} | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
367 186 151 | |
179 10 203 | |
271 37 39 | |
103 230 1 | |
27 104 185 | |
253 50 85 | |
1 1 1 | |
9075 337 210 | |
307 24 79 | |
331 221 177 | |
259 170 40 | |
269 58 102 | |
0 0 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmd /k "g++ eratosthenes.cc & a.exe < input.txt" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment