Topic 1040:prime Number

Source: Internet
Author: User

Topic 1040:prime Number

time limit:1 seconds

Memory limit:32 MB

Special question: No

Title Description:

Output the k-th prime number.

Input:

k≤10000

Output:

The k-th prime number.

Sample input:
37
Sample output:
517
Thinking of solving problems: prime Selection method
Note: The title requirement is the output 1000 in any one prime, the size of the array declared as 1000 is far from enough, the program running results show the 1000th prime number is 7919, so the array to declare a larger point.
First commit because the array is small
#include <iostream>#include<stdio.h>#include<string.h>#include<algorithm>#include<stack>#include<math.h>using namespacestd;# define Len200000intPrime[len];//used to store prime numbersintPrimesize;//number of vegetarian charactersBOOLMark[len];//Mark whether a number is primevoidinit () {primesize=0;//Number of characters initialized to 0    Long Long inti,j;  for(i=0; i<len; i++) {Mark[i]=false;//true to indicate that it is not a prime number    }     for(i=2; i<len; i++)    {        if(mark[i]==true)Continue;//not primes continue        Else{prime[primesize++]=i;  for(J=i*i; j<len; j+=i) {mark[j]=true; }        }    }}intMain () {init (); intN;  while(SCANF ("%d", &n)! =EOF) {printf ("%d\n", prime[n-1]); }    return 0;}

Topic 1040:prime Number

Related Article

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.