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

#SP0000188. Những số yêu thích của Ringo 3

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Những số yêu thích của Ringo 3

Ringo's Favorite Numbers 3

Source: AtCoder ABC400 E
Version: Phuoc Hung OJ Extended (one dataset per execution; batched queries remain together).

Problem Statement

A positive integer xx is a 400-number if it has exactly two distinct prime factors and every prime factor has an even exponent. For each of QQ queries AA, find the largest 400-number not exceeding AA. The answer always exists.

Input

The first line contains QQ. Each of the following QQ lines contains an integer AA.

Output

Print one answer per query, each on its own line.

Subtasks

  • Subtask 1 (20 points): 1≤Q≤301\le Q\le30 và 36≤A≤10636\le A\le10^6.
  • Subtask 2 (30 points): 1≤Q≤50001\le Q\le5000 và 36≤A≤101036\le A\le10^{10}.
  • Subtask 3 (50 points): 1≤Q≤2⋅1051\le Q\le2\cdot10^5 và 36≤A≤101236\le A\le10^{12}.

Sample Input

5
404
36
60
1000000000000
123456789

Sample Output

400
36
36
1000000000000
123454321

Sample Explanation

400=24⋅52400=2^4\cdot5^2 satisfies both conditions; 401,402,403,404401,402,403,404 do not, so the answer to A=404A=404 is 400400.