hdu 2138 How many prime numbers

简介:

http://acm.hdu.edu.cn/showproblem.php?pid=2138

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
bool isprime(int m)
{
    if(m == 1)
        return 0;
    int n=sqrt((double)m);
    for(int i=2; i<=n; i++)
      if(m%i == 0)
        return 1;
    return 0;
}
int main()
{
    int m,n;
    while(~scanf("%d",&m))
    {
        int sum=0;
        while(m--)
        {
            scanf("%d",&n);
            if(!isprime(n))
                sum++;
        }
        printf("%d\n",sum);
    }
    return 0;
}
目录
相关文章
UVa11679 - Sub-prime
UVa11679 - Sub-prime
54 0
HDU-1061,Rightmost Digit(快速幂)
HDU-1061,Rightmost Digit(快速幂)
|
算法
HDOJ(HDU) 2161 Primes(素数打表)
HDOJ(HDU) 2161 Primes(素数打表)
111 0
|
机器学习/深度学习
|
人工智能
|
安全
D-POJ-3126 Prime Path
Description The ministers of the cabinet were quite upset by the message from the Chief of...
1126 0
|
机器学习/深度学习 Java
|
人工智能 Java