Advertisement
Centipede18

sangnt

Mar 26th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4. const int MAXSANG = 10000;
  5.  
  6. int snt[MAXSANG+1];
  7.  
  8. void sangnt(){
  9.     long i,j;
  10.     for (i=1; i<=MAXSANG; i++){
  11.         snt[i]=1;
  12.     }
  13.         snt[1]=0;
  14.         i=2;
  15.     while (i<=sqrt(MAXSANG)){
  16.         while (snt[i]==0)
  17.             i++;
  18.         for (j=2; j<=MAXSANG/i; j++){
  19.             snt[i*j]=0;
  20.         }
  21.         i++;
  22.     }
  23. }
  24.  
  25. int main()
  26. {
  27.     sangnt();
  28.     for (int i=1; i<=10000; i++)
  29.     if (snt[i]) cout<< i<<endl;
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement