判断素数

#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;
    }

}
原文地址:https://www.cnblogs.com/TheRoadToTheGold/p/6219729.html