AlexandruT

Ciurul lui Eratostene

Dec 9th, 2014
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.32 KB | None | 0 0
  1. int a[45002], n;
  2. int prime[5000], k;
  3.  
  4. void Ciur(int n)
  5. {
  6.     int i, j;
  7.     for(i = 3; i * i <= n; i += 2)
  8.         if(a[i] == 0)
  9.             for(j = i * i; j <= n; j = j + 2 * i)
  10.                 a[j] = 1;
  11.     k = 0;
  12.     prime[++k] = 2;
  13.     for(i = 3; i <= n; i += 2)
  14.         if(a[i] == 0)
  15.             prime[++k] = i;
  16. }
Advertisement
Add Comment
Please, Sign In to add comment