HDU-2138 How many prime numbers

来源:互联网 发布:vb控件适应窗体大小 编辑:程序博客网 时间:2024/06/05 11:22

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

简单的求素数个数题 :

#include <iostream>#include <cstdlib>#include <cstdio>#include <cmath>#include <iomanip>#include <string>#include <set>#include <map>#include <queue> #include <stack>#include <vector>#include <algorithm>#include <sstream> #include <cstring>using namespace std;bool judge(int x){    for(int i=2;i<=sqrt(x);i++)    {        if(x%i==0)            return true;    }    return false;} int main(){    int n,t;    while(cin>>n)    {        int ans=0;        while(n--)        {            cin>>t;            if( judge(t)==false )                ans++;        }        cout<<ans<<endl;    }    return 0;} 
原创粉丝点击