Saleh127

Untitled

May 27th, 2020
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define M 1000000
  4. bool marked[M];
  5. bool isPrime(int n)
  6. {
  7. if (n < 2)
  8. return false;
  9. if (n == 2)
  10. return true;
  11. if (n % 2 == 0)
  12. return false;
  13. return marked[n] == false;
  14. }
  15. void sieve(int n)
  16. {
  17. for (int i = 3; i * i <= n; i += 2)
  18. {
  19. if (marked[i] == false) // i is a prime
  20. {
  21. for (int j = i * i; j <= n; j += i + i)
  22. {
  23. marked[j] = true;
  24. }
  25. }
  26. }
  27. }
  28.  
  29. int main()
  30. {
  31. int a,b,c,i;
  32. cin>>a;
  33. if(isPrime(a)== true) cout<<a<<" "<<"Prime\n";
  34. else cout<<a<<" "<<"Not Prime\n";
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment