判断素数

#include<iostream>
#include<cmath>
using namespace std;
int b;
int main()
{
    while(cin>>b)
    {
        bool ok=false;
        for(int i=2;i<=sqrt(b);i++)
        {
            if(b%i==0)
            {
                ok=true;
                cout<<i<<' ';
                cout<<"NO"<<endl;
                break;
            }
        }
        if(!ok) cout<<"YES"<<endl;
    }

}

 

posted @ 2016-12-25 15:56  TRTTG  阅读(242)  评论(0编辑  收藏  举报