PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SP0000068. Tìm số nguyên tố thứ K (Finding the Kth Prime)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Tìm số nguyên tố thứ K (Finding the Kth Prime)

Finding the Kth Prime

Source: SPOJ

Version: Phuoc Hung OJ Extended

Problem Statement

List the primes in increasing order, 2,3,5,7,11,…2,3,5,7,11,\ldots, indexed from 11 (so the first prime is 22). Given QQ independent queries, answer query ii with the value of the KiK_i-th prime. Preserve the input query order.

Input

The first line contains integer QQ. Each of the next QQ lines contains one integer KiK_i.

Output

Print exactly QQ lines; line ii is the KiK_i-th prime.

Subtasks

  • Subtask 1 (20 points): 1≤Q≤1001\le Q\le 100; 1≤Ki≤10001\le K_i\le 1000 for every 1≤i≤Q1\le i\le Q.
  • Subtask 2 (30 points): 1≤Q≤50001\le Q\le 5000; 1≤Ki≤1000001\le K_i\le 100000 for every 1≤i≤Q1\le i\le Q.
  • Subtask 3 (50 points): 1≤Q≤500001\le Q\le 50000; 1≤Ki≤50000001\le K_i\le 5000000 for every 1≤i≤Q1\le i\le Q.

Examples

Input

7
1
10
100
1000
10000
100000
1000000

Output

2
29
541
7919
104729
1299709
15485863

Explanation

The first prime is 22 and the tenth is 2929. Positions 100,1000,10000,100000,1000000100,1000,10000,100000,1000000 give 541,7919,104729,1299709,15485863541,7919,104729,1299709,15485863, respectively. There are exactly seven output lines, matching the seven queries.