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;
}
目录
相关文章
|
9月前
UVa11679 - Sub-prime
UVa11679 - Sub-prime
34 0
HDU-1061,Rightmost Digit(快速幂)
HDU-1061,Rightmost Digit(快速幂)
|
机器学习/深度学习
POJ 1775 (ZOJ 2358) Sum of Factorials
POJ 1775 (ZOJ 2358) Sum of Factorials
122 0
|
机器学习/深度学习
|
安全
D-POJ-3126 Prime Path
Description The ministers of the cabinet were quite upset by the message from the Chief of...
1108 0
|
人工智能 Java
|
人工智能 机器学习/深度学习
POJ 1775 (ZOJ 2358) Sum of Factorials
Description John von Neumann, b. Dec. 28, 1903, d. Feb. 8, 1957, was a Hungarian-American mathematician who made important contributions t...
1114 0
|
人工智能 Java BI
容斥 - HDU 4135 Co-prime
Co-prime  Problem's Link:  http://acm.hdu.edu.cn/showproblem.php?pid=4135 推荐: 容斥原理 Mean:  给你一个区间[l,r]和一个数n,求[l,r]中有多少个数与n互素。
888 0