-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patht24.cpp
37 lines (35 loc) · 872 Bytes
/
t24.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
long long int exponentiation(long long int a, long long int b, long long int M)
{
if (b == 0)
return 1;
else if (b % 2 == 0)
return exponentiation((a * a) % M, b / 2, M);
else
return (((a % M) * exponentiation((a * a) % M, (b - 1) / 2, M)) % M);
}
int main()
{
int t;
cin >> t;
while (t--)
{
long long int n, k, ans;
cin >> n >> k;
if (k == 1)
ans = 1;
else
{
long long int num = exponentiation(k, n, mod);
num -= 1;
num = ((k % mod) * (num % mod)) % mod;
long long int den = k - 1;
den = exponentiation(den, mod - 2, mod);
ans = ((num % mod) * (den % mod)) % mod;
}
cout << ans << "\n";
}
return 0;
}