返回列表 發帖
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.     bool isPrime = true;
  6.     int n;
  7.     cin >> n;
  8.     for(int i=2 ; i<=sqrt(n) ; i++)
  9.     {
  10.         if(!(n%i))
  11.             isPrime = false;
  12.     }
  13.     if(isPrime)
  14.         cout << n << " is a prime number\n";
  15.     else
  16.         cout << n << " is not a prime number\n";
  17.     return 0;
  18. }
複製代碼
Vincent

TOP

返回列表