AMR11E - Distinct Primes


Arithmancy is Draco Malfoy's favorite subject, but what spoils it for him is that Hermione Granger is in his class, and she is better than him at it. Prime numbers are of mystical importance in Arithmancy, and Lucky Numbers even more so. Lucky Numbers are those positive integers that have at least three distinct prime factors; 30 and 42 are the first two. Malfoy's teacher has given them a positive integer n, and has asked them to find the n-th lucky number. Malfoy would like to beat Hermione at this exercise, so although he is an evil git, please help him, just this once. After all, the know-it-all Hermione does need a lesson.

Input

The first line contains the number of test cases T. Each of the next T lines contains one integer n.

Output

Output T lines, containing the corresponding lucky number for that test case.

Constraints

1 <= T <= 20
1 <= n <= 1000

Example

Sample Input:
2
1
2

Sample Output:
30
42

hide comments
scorpion_ajay: 2017-03-11 19:47:15

no sieve, nothing, its just too simple... play smart.
HINT : "atleast" word stole the show ;P

nilabja16180: 2017-03-10 11:15:27

AC in ONE GO 0.00sec!
1000th prime is 2664!
2sec is too much

supercool2204: 2016-12-01 08:27:26

see <snip>

[NG]: Consider ACing first before giving advices to others.

Last edit: 2021-04-21 13:41:21
fahim5466: 2016-11-09 19:11:17

u dnt need sieve or any brute force! the solution can be efficiently found without any brute force by applying simple divisibility testing

fahim5466: 2016-11-09 19:09:07

The tricky thing here is that the problem says numbers which have 'AT LEAST' 3 distinct prime factors meaning numbers with more than 3 distinct prime factors are also lucky!

sas1905: 2016-10-28 19:55:34

Pre Computation with the help of Sieve..1000th lucky number is 2664..:)

philip97hd: 2016-10-20 16:47:35

How are they counting the numbers , How to calculate the "n == 5" number it ?!

Last edit: 2016-10-20 16:49:13
manavkothari: 2016-10-11 05:56:31

how to see solution of problems i dont understand

rishabh_1997: 2016-09-19 06:48:55

Nice question... Sieve & Some smart work.

itsnaveen01: 2016-09-18 13:35:42

Sieve And Hashing !!


Added by:Varun Jalan
Date:2011-12-15
Time limit:3s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Varun Jalan - ICPC Asia regionals, Amritapuri 2011