素数判断

#include<bits/stdc++.h>
using namespace std;


int check(int n)
{
    for(int i=2;i*i<=n;i++)//因数不超过根号n 
        if(n%i==0) return false;
        return true; 
}//时间复杂度为根号n

int main()
{
    int a;
    while(cin>>a)
    {
        cout<<check(a)<<endl;
    }
    return 0;
}
原文地址:https://www.cnblogs.com/KyleDeng/p/15553308.html