输入样例:
3 4 3 8 5 6 3
输出样例:
1 2 impossible
#include<iostream> using namespace std; typedef long long LL; int qmi(int a, int b, int p) { int res = 1; while(b) { if(b & 1) res = (LL) res * a % p; b >>= 1; a = (LL) a * a % p; } return res; } int main() { int n; cin >> n; while(n --) { int a, p; cin >> a >> p; if(a % p ) cout << qmi(a, p - 2, p) << endl; else puts("impossible"); } return 0; }