Advertisement
1jn2h0n0th3xac

[C++] Kiểm tra số nguyên tố

Jul 30th, 2015
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.29 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. bool test(long prime)
  6. {
  7.     for (i = 2; i <= sqrt(prime); i++){
  8.         if (prime % i == 0) return false;
  9.     }
  10.     return true;
  11. }
  12.  
  13. int main()
  14. {
  15.     long x;
  16.     cin >> x;
  17.     if (test(x)){
  18.         cout << "yes\n";
  19.     }
  20.     else{
  21.         cout << "no\n";
  22.     }
  23.     system("pause");
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement