Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include<cstdio>
  2. #include <cmath>
  3.  
  4. #define MAXN 10000005
  5. using namespace std;
  6.  
  7. bool composto[MAXN];
  8.  
  9. void crivo()
  10. {
  11.     composto[1] = 1;
  12.     for(int i = 2; i<=sqrt(MAXN); ++i)
  13.     {
  14.         if(!composto[i])
  15.         {
  16.             for(int j = i*i; j<=MAXN; j+=i)
  17.             {
  18.                 composto[j] =1;
  19.             }
  20.         }
  21.     }
  22. }
  23.  
  24. int main()
  25. {
  26.     crivo();
  27.  
  28.     int n, a;
  29.     scanf("%d", &n);
  30.     while(n--)
  31.     {
  32.         scanf("%d", &a);
  33.         if(composto[a])
  34.             printf("%d nao eh primo\n", a);
  35.         else
  36.             printf("%d eh primo\n", a);
  37.     }
  38.  
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement