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;
}
目录
相关文章
HDU-1061,Rightmost Digit(快速幂)
HDU-1061,Rightmost Digit(快速幂)
|
算法
HDOJ(HDU) 2136 Largest prime factor(素数筛选)
HDOJ(HDU) 2136 Largest prime factor(素数筛选)
118 0
|
人工智能
|
Java
HDU 1021 Fibonacci Again
Fibonacci Again Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 58267    Accepted Submission(...
908 0