Advertisement
nasarouf

primes generation

Apr 20th, 2017
716
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.25 KB | None | 0 0
  1. //Primes. Sieve of Eratosthenes
  2. //nasarouf@cs.ubc.ca
  3. int p[MAX],pc,f[MAX+1];
  4. void gen() {
  5.     pc = 0; p[pc++] = 2;
  6.     for (int i = 3; i <= MAX; i += 2) if (!f[i]) {
  7.         p[pc++] = i;
  8.         if (i <= MAX / i) for (int j = i*i; j <= MAX; j += 2 * i) f[j] = 1;
  9.     }
  10. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement