#413: 能否幫我看看我哪裡出錯,感恩!


monyen (BenQ)


#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    int a ;    
    bool IsPrime ;
    
    while(cin >> a)
    {
       IsPrime = 1 ;
       if(a==2)
       {
          cout << "質數" << endl ;
          continue;
       }
       else
       {
            int i = sqrt(a) ;
            
            while(i != 1)
            {
               if(a%i==0)
                  IsPrime = 0 ;
               i -= 1 ;
            }
       }
       
       if(IsPrime == 1)
          cout << "質數" << endl ;
       else
          cout << "非質數" << endl ;   
    }
    return 0 ;
}