Poj2928: Number of prime numbers

Source: Internet
Author: User
Total time limit: 1000 ms memory limit: 65536kb describe to judge between 11 and any integer smaller than 1000 and greater than 11, which is both a prime number and a return number. Enter an integer greater than 11 and less than 1000. The number between 11 and the input number is both a prime number and a number of input. Sample input: 999543 sample output: 1610 indicates that there are multiple groups of test data. Use while () to input them cyclically. The number of input is symmetric between the left and right, for example, 292,333.

The data size of this question is not large. You can mark the prime number and then judge it.

The Code is as follows:

#include <iostream>#include <stdio.h>using namespace std;int f[1000]={0};int coun = 0;void init(){    for(int i = 2; i < 1000; i++)    {        if(f[i] == 0)        {            for(int j = i+i; j < 1000; j+=i)            {                f[i] = 1;            }        }    }}int main(){    init();    int n;    int coun = 0;    while(cin>>n)    {        coun = 0;        for(int i = 11; i < n; i++)        {            if(f[i] == 0)            {                if(f[i]/100 == 0)                {                    if(i%10 == i/10)                        coun++;                }                else                {                    if(i%10 == i/100)                        coun++;                }            }        }        cout<<coun<<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.