This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
files:cpp:primesieve [2018/08/10 09:09] jguerin Crated, added Kattis source, explanation. |
files:cpp:primesieve [2018/09/14 16:35] (current) jguerin Moved the first sentence to the explanation header as a terse explanation. |
||
---|---|---|---|
Line 18: | Line 18: | ||
vector< | vector< | ||
+ | # Implemented from Wikipedia | ||
void sieve(int n) { // eratosthenes as a drop-in solution | void sieve(int n) { // eratosthenes as a drop-in solution | ||
nums.set(); | nums.set(); | ||
Line 31: | Line 31: | ||
int n, q, x, total=0; | int n, q, x, total=0; | ||
- | cin >> n >> q; | + | cin >> n >> q; |
- | sieve(n); | + | sieve(n); |
- | for(int i=2; i<=n; i++) // count primes in range | + | for(int i=2; i<=n; i++) // count primes in range |
if(nums[i]) | if(nums[i]) | ||
total++; | total++; | ||
| | ||
- | cout << total << endl; | + | cout << total << endl; |
- | for(int i=0; i<q; i++) { // query, print results from flags | + | for(int i=0; i<q; i++) { |
cin >> x; | cin >> x; | ||
if(nums[x]) | if(nums[x]) | ||
Line 53: | Line 53: | ||
===== Solution Explanation ===== | ===== Solution Explanation ===== | ||
- | The title of the problem is a strong hint towards its intent to educate the reader about Prime Sieves. Python3 can be immediately ruled out as a //likely// solution due to the problem bounds. Note that you need to compute 1 ≤ //n// ≤ 10< | + | The title of the problem is a strong hint towards its intent to educate the reader about Prime Sieves. |
+ | |||
+ | ==== Potential " | ||
+ | Python3 can be immediately ruled out as a //likely// solution due to the problem bounds. Note that you need to compute 1 ≤ //n// ≤ 10< | ||
+ | |||
+ | The second thing thing that we can most likely rule out is the //storage// of each prime. Note that the problem doesn' | ||
- | The second thing thing that we can most likely rule out is the // | + | ==== Finding the Solution ==== |
+ | Once we understand | ||