Ar3mida

k_5

Nov 2nd, 2019
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. bool IsPrime(int n) {
  7.     int min_divisor = 1;
  8.     int sqrt_n = sqrt((double)n);
  9.     for (int i = 2; i <= sqrt_n; i++) {
  10.         if (n % i == 0)
  11.         {
  12.             min_divisor = i;
  13.             break;
  14.         }
  15.     }
  16.     if (min_divisor == 1)
  17.         return true;
  18.     else
  19.         return false;
  20. }
  21.  
  22. int main() {
  23.     int n;
  24.     cin >> n;
  25.     if (IsPrime(n)) cout << "YES";
  26.     else cout << "NO";
  27.     return 0;
  28. }
Add Comment
Please, Sign In to add comment