Advertisement
Guest User

Untitled

a guest
Aug 26th, 2016
611
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. const int LIMIT = 1000000;
  2.  
  3. int sieve[LIMIT + 1];
  4. int primes[LIMIT + 1];
  5. int L[LIMIT+1];
  6. int primeCount = 1;
  7.  
  8. void gensieve() {
  9.     CLR(sieve, 0);
  10.     for (int i = 2; i <= LIMIT; i++) {
  11.         if (!sieve[i]) {
  12.             primes[primeCount] = i;
  13.             sieve[i] = primeCount++;
  14.         }
  15.         for (int j = 1; j <= sieve[i] && i * primes[j] <= LIMIT; j++) {
  16.             sieve[i * primes[j]] = j;
  17.         }
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement