Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <math.h>
- #include <iostream>
- using namespace std;
- // число должно быть >= 2
- bool isPrime(int x) {
- x = fabs(x);
- if (x == 2) {
- return true;
- }
- if (x < 2) {
- return false;
- }
- for (int i = 2; i <= ceil(sqrt(x)); i++) {
- if (x % i == 0) {
- return false;
- }
- }
- return true;
- }
- int main() {
- int x;
- cin >> x;
- if (isPrime(x)) {
- cout << "true\n";
- } else {
- cout << "false\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement