HDU Topic 2138 How many prime numbers

Source: Internet
Author: User
Tags time limit
How many prime numbers

Time limit:3000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 11330 Accepted Submission (s): 3921


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 Input
3
2 3 4


Sample Output

2

C + +, when using the SQRTQ function, it is necessary to change the number of the root of the mandatory load into floating-point type, if the radicals is a floating-point type is irrelevant.

#include <iostream>
#include <fstream>
#include <math.h>
using namespace std;

int is_prime (int m)
{
    if (m==0| | m==1)
        return 0;
    else if (m==2)
        return 1;
    for (int i=2;i<=sqrt (double) m); i++)
    {
        if (m%i==0)
            return 0;
    }
    return 1;
}

int main (void)
{
    //ifstream cin ("2138.txt");
    int n;
    int m;
    char ch;
    while (Cin>>n)
    {
        int sum=0;
        for (int i=1;i<=n;i++)
        {
           //cin>>ch;
                int t;
                cin>>t;
                if (Is_prime (t))
                    sum++;

        }
         cout<<sum<<endl;
    }

    return 0;
}


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.