problems / 164

Alice's Integer Roots

easy binary-search math 1000 ms · 256 MB

Alice's Integer Roots

Bob has found a new way to keep Alice busy. He writes a huge number n on the board, names an exponent k, and asks: "What is the largest whole number which, multiplied by itself k times, still doesn't exceed my number?" Alice is quick, but Bob has prepared a long list of these questions, and some of his numbers sit just one away from a perfect power, which is exactly where guessing goes wrong.

Formally, for each query (n, k) find the largest positive integer x such that x^k ≤ n.

Input

The first line contains an integer t (1 ≤ t ≤ 10^5), the number of queries.

Each of the next t lines contains two integers n and k (1 ≤ n ≤ 10^18, 1 ≤ k ≤ 60).

Output

For each query, print on its own line the largest positive integer x with x^k ≤ n. Since n ≥ 1, the answer is always at least 1.

Notes

In the first example, 3^2 = 9 ≤ 10 but 4^2 = 16 > 10, so the answer is 3. The number 27 is exactly 3^3, so its answer is 3, while for 26 it drops to 2.

In the second example, 10^18 = (10^9)^2, and one less than that already has answer 999999999. The number 576460752303423488 equals 2^59.

Example 1

Input

5
10 2
27 3
26 3
1000000000000000000 1
1 60

Output

3
3
2
1000000000000000000
1

Example 2

Input

5
1000000000000000000 2
999999999999999999 2
576460752303423488 59
576460752303423487 59
1000000000000000000 60

Output

1000000000
999999999
2
1
1

Hints · reveal one at a time if you're stuck

Hint 1

For a fixed k, the test x^k ≤ n is true for every x up to the answer and false above it. What search method does that suggest?

Hint 2

Binary search on x, with an upper bound of 10^9 when k is at least 2. Compute the power while stopping as soon as it would exceed n, since a wrapped product can pass the test, and avoid trusting floating-point roots near perfect powers.

report an issue Prefer your own editor? sooks prep 164 (CLI)
Sign in to run code

Run your code on the examples, or submit it against every test.