You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
400 B

#include <bits/stdc++.h>
using namespace std;
#define int long long
int n;
int qmi(int a, int k, int p) {
int res = 1;
while (k) {
if (k & 1) res = res * a % p;
k >>= 1;
a = a * a % p;
}
return res;
}
signed main() {
cin >> n;
while (n--) {
int a, k, p;
cin >> a >> k >> p;
printf("%d\n", qmi(a, k, p));
}
return 0;
}