Advertisement
Guest User

Untitled

a guest
Mar 24th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. #include <math.h>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. // число должно быть >= 2
  6. bool isPrime(int x) {
  7. x = fabs(x);
  8. if (x == 2) {
  9. return true;
  10. }
  11. if (x < 2) {
  12. return false;
  13. }
  14. for (int i = 2; i <= ceil(sqrt(x)); i++) {
  15. if (x % i == 0) {
  16. return false;
  17. }
  18. }
  19. return true;
  20. }
  21.  
  22. int main() {
  23. int x;
  24. cin >> x;
  25. if (isPrime(x)) {
  26. cout << "true\n";
  27. } else {
  28. cout << "false\n";
  29. }
  30. return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement