Advertisement
Mirbek

Простое ли число?

Jan 5th, 2022
477
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. bool isPrime(int x) {
  6.     if (x < 2) return 0;
  7.     int sq = sqrt(x);
  8.     for (int i = 2; i <= sq; i++) {
  9.         if (x % i == 0) {
  10.             return false;
  11.         }
  12.     }
  13.     return true;
  14. }
  15.  
  16. int main(){
  17.     int n;
  18.     cin >> n;
  19.  
  20.     if (isPrime(n)) {
  21.         cout << "Yes\n";
  22.     } else {
  23.         cout << "No\n";
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement