HDOJ 2161 Primes (数论)

//超级水题,热身的,没必要解释
//http://acm.hdu.edu.cn/showproblem.php?pid=2161
#include<iostream>
using namespace std;

bool IsPrime(int n)
{
    int i = 0;
    if(n<=2) return false;
    for(i=2;i*i<=n;i++)
    {
        if(n%i==0)
            return false;
    }
    return true;
}

int main()
{
    int i,N;
    int count = 0;
    while(scanf("%d",&N)!=EOF&& N>0 )
    {
        count++;
        if(IsPrime(N))
            printf("%d: yes
",count);
        else
             printf("%d: no
",count);
    }
    return 0;
}
原文地址:https://www.cnblogs.com/Lee-geeker/p/3375060.html