TDKPRIME - Finding the Kth Prime


The problem statement is really simple. There are some queries. You are to give the answers.

Input

An integer stating the number of queries Q(equal to 50000), and Q lines follow, each containing one integer K between 1 and 5000000 inclusive.

Output

Q lines with the answer of each query: the Kth prime number.

Example

Input:
7
1
10
100
1000
10000
100000
1000000

Output:
2
29
541
7919
104729
1299709
15485863

hide comments
ayushgupta1997: 2017-12-09 11:53:04

Simple Problem ,attempted after 1 year AC in one go :)
Hint : Sieve precomputation, declare array global with MAX=87000008

Sushant Moon: 2017-10-06 00:01:57

Is there some problem with the test cases, i checked/compared/double-checked the prime numbers generated by my sieve for first 5million primes, with 5million primes from https://primes.utm.edu/lists/small/millions/, they check out all of them are correct. But the test cases is giving me WA.

My submission ID is 20301637

Last edit: 2017-10-06 00:48:58
kmkhan_014: 2017-08-28 13:20:24

took 0.6 s...how to improve upon time

harsh123_: 2017-01-25 05:28:13

Use Segmented Sieve...Took only 3.4MB space
But how to make it time efficient..It took 0.67 sec

Last edit: 2017-01-25 05:28:55
madhavgaba: 2017-01-15 19:01:58

how can the top solution be 3.4M and 0.04 sec!!!!

vivace: 2016-12-22 23:04:16

also , how is the memory use just 3.6 MB for best AC solution as per time limit.. sieve+an array till required takes 22MB in my case

vivace: 2016-12-22 23:02:54

how are people getting 0.04 seconds while my nloglogn sieve of eratosthenes, several loop counter modifications alongwith scanf and printf got 0.56?

iharsh234: 2016-07-08 11:44:04

do it just for bitwise seive.
cool problem
bitwise seive - > 0.45 sec
linear seive -> 0.75 sec

Last edit: 2016-07-08 11:59:28
blueranger: 2016-06-15 20:07:19

@Alfonso2 Peterssen Last submitted solution is working perfectly on my machine. Can you please tell me why am I getting WA?

surya2196: 2016-04-05 19:12:44

lolypop question


Added by:Alfonso² Peterssen
Date:2010-04-06
Time limit:1.240s
Source limit:10000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM32 ASM64 BF CLPS LISP sbcl LISP clisp ERL HASK ICON ICK JS-RHINO LUA NEM NICE OBJC OCAML PHP PIKE PRLG-swi SCALA SCM guile SCM qobi ST SQLITE TCL WHITESPACE
Resource:Thanks to TDuke