hdu acmsteps 2.1.2 How many prime numbers

How many prime numbers

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

Total Submission(s): 5139 Accepted Submission(s): 1684

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
   1:  #include<iostream>
   2:  #include<cmath>
   3:  using namespace std;
   4:  bool isPrime(int n){
   5:      int sqt=sqrt(n*1.0);
   6:      for(int i=2;i<=sqt;i++)
   7:          if(n%i==0)
   8:              return false;
   9:      return true;
  10:  }
  11:  int main(){
  12:      //freopen("in.txt","r",stdin);
  13:      for(int n;cin>>n;){
  14:          int num=0,temp;
  15:          while(n--){
  16:              cin>>temp;
  17:              num+=isPrime(temp);
  18:          }
  19:          cout<<num<<'\n';
  20:      }
  21:  }
判断素数;
posted @ 2013-04-06 00:44  姜楠  阅读(198)  评论(0编辑  收藏  举报