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

#SP0000176. Số nguyên tố ghép

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Số nguyên tố ghép

Concatenated Prime Numbers

Source: VNOJ mprime
Version: Phuoc Hung OJ Extended (one dataset per execution; batched queries remain together).

Problem Statement

Let p1,p2,…p_1,p_2,\ldots be all primes in increasing order. Concatenate each pair of consecutive primes in decimal to form bib_i; e.g. 2323, 5757, 11131113, 17191719. Retain only those bib_i which themselves are prime, in original order. Find the KK-th retained value.

Input

One integer KK.

Output

Print the KK-th concatenated prime.

Subtasks

  • Subtask 1 (20 points): 1≤K≤201\le K\le 20.
  • Subtask 2 (30 points): 1≤K≤1501\le K\le 150.
  • Subtask 3 (50 points): 1≤K≤5001\le K\le 500.

Sample Input

2

Sample Output

3137

Sample Explanation

2323 is the first concatenated prime. The second is 31373137, formed from consecutive primes 3131 and 3737.