您的位置:首页 > 其它

HDU 2138 How many prime numbers 质数个数

2014-06-20 11:10 441 查看

How many prime numbers

Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 12383 Accepted Submission(s): 4284


Problem Description
Give you a lot of positive integers, just to find out how many prime numbers there are.
Input
There are a lot of cases. In each case, there is an integer N representing the number of integers to find. Each integer won’t exceed 32-bit signed integer, and each of them won’t be less than 2.
Output
For each case, print the number of prime numbers you have found out.
Sample Input

3
2 3 4


Sample Output

2


题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2138

/*
 2138 ( How many prime numbers ) 判断质数的个数 
*/

#include<stdio.h>
#include <math.h>
//using namespace std;

int main(){   
    int i,j,f,k,n,m,b;
   
   while(scanf("%d",&n)!=EOF)
    {
    k=0;                         
    for(i=0;i<n;i++)
    {
        scanf("%d",&m);
        f=0;
        b=sqrt(m);
        for(j=2;j<=b;j++)
        if(m%j==0) 
        {f=1;break;}
        if(f==0) k++;
    }
    printf("%d\n",k);
    }
    return 0;
    }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: