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

TOP

返回列表