No.1287 NK
タグ : / 解いたユーザー数 106
作問者 :
Problem Statement
You are given integers $X,K$.
Find an integer $N$ such that $X = N^K\ \mathrm{mod}\ (10^9+7)$.
Answer for $T$ test cases.
Constraints
- $X,K,T$ are integers
- $1 \le T \le 10^5$
- $0 \le X < 10^9+7$
- $1 \le K \le 5 \times 10^8$
- $K$ is odd
Input
$T$
First, an integer $T$, the number of test cases, is given on $1$ line.
Then, the following is given over $T$ lines.
$X$ $K$
The integers $X,K$ are given on $1$ line, separated by a space.
Output
For each test case, output as follows.
Output the integer $N$ on $1$ line. Print a newline at the end.
Here, $N$ must satisfy the following constraints.
- $0 \le N < 10^9+7$
- $X = N^K\ \mathrm{mod}\ (10^9+7)$
It can be proved that, for the given input and these constraints, exactly one solution exists.
Sample
Sample 1
Input
3
32 5
1000 3
4096 3
Output
2
10
16
We have $32 = 2^5$ , $1000 = 10^3$ , $4096 = 16^3$ .
Sample 2
Input
3
1000000000 1
1000000000 3
1000000000 9
Output
1000000000
1000
10
We have $1000000000 = 1000000000^1$ , $1000000000 = 1000^3$ , $1000000000 = 10^9$ .
Sample 3
Input
3
1000000006 11
1000000006 13
1000000006 15
Output
1000000006
1000000006
1000000006
Sample 4
Input
5
337716880 91488205
413500684 972383
499738548 34626483
901106148 239798535
230314780 62951413
Output
314159265
358979323
846264338
327950288
419716939
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。