返回列表 發帖
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int compute(int n)
  4. {
  5.     for(int i=2;i<=sqrt(n);i++)
  6.     {
  7.         if(n%i==0)
  8.         return 0;
  9.     }
  10.     return 1;

  11. }
  12. int main()
  13. {
  14.     int n;
  15.     cin>> n;
  16.     if(compute(n))
  17.         cout<<n<<" is a prime number\n";
  18.     else
  19.         cout<<n<<" is not a prime number\n";


  20.     return 0;
  21. }
複製代碼

TOP

返回列表