#include <bits/stdc++.h>
using namespace std;
typedef long long lld;
const int MOD = 1e9 + 7;
int gcd(int a, int b)
{
return b ? gcd(b, a % b) : a;
}
int fpow(int n, int k)
{
if(k == 0) return 1;
if(k % 2){
return 1ll * n * fpow(n, k - 1) % MOD;
}
int h = fpow(n, k / 2);
return 1ll * h * h % MOD;
}
int main()
{
int t;
cin >> t;
while(t--){
int n, k;
cin >> k >> n;
int g = gcd(k, n);
k /= g;
n /= g;
cout << (1ll * n * fpow(k, MOD - 2) % MOD) << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
28 ms |
1720 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |