How many prime numbers (number of counts)

Source: Internet
Author: User

How many prime numbers

Time limit:3000/1000 MS (java/others) Memory limit:32768/32768 K (java/others) total submission (s): 14684 Accepted Submission (s): 5091

Problem Description Give you a lot of positive integers, just to find out how many prime numbers there is.

Input There is a lot of cases. In each case, there is a integer N representing the number of integers to find. Each of the integer won ' t exceed 32-bit signed integer, and each of the them won ' t is less than 2.

Output for each case, print the number of prime numbers you has found out.

Sample Input32 3 4

Sample Output2

Exercises

Water violence, play table not, because the data volume is too large, run to sqrt (x) can;

Code:

#include <cstdio>#include<cstring>#include<cmath>#include<algorithm>using namespacestd;BOOLjsintx) {    if(x==2)return true; if(x==1|| x==0)return false; if(%2==0)return false;  for(intI=3; i<=sqrt (x); i+=2){        if(x%i==0)return false; }    return true;}intMain () {intN,a;  while(~SCANF ("%d",&N)) {        intCnt=0;  for(intI=0; i<n;i++) {scanf ("%d",&a); if(JS (a)) cnt++; } printf ("%d\n", CNT); }    return 0;}

How many prime numbers (number of counts)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.