我也没看出你哪错了qwq
我的代码:
```cpp
#include <iostream>
#include <unordered_map>
#include <cmath>
using namespace std;
typedef long long ll;
unordered_map<ll, ll> mp;
inline ll quick_pow(ll x, ll p, ll mod){
ll ans = 1;
while (p){
if (p & 1) ans = ans * x % mod;
x = x * x % mod;
p >>= 1;
}
return ans;
}
inline ll bsgs(ll a, ll b, ll p){
a %= p;
b %= p;
if (b == 1) return 0;
if (a == 0) return b == 0 ? 1 : -1;
ll m = sqrt(p) + 1, x, y = 1, z;
mp.clear();
x = b;
z = quick_pow(a, m, p);
mp[x] = 0;
for (register ll i = 1; i < m; i++){
x = x * a % p;
mp[x] = i;
}
for (register ll i = 1; i <= m; i++){
y = y * z % p;
if (mp.count(y)){
return i * m - mp[y];
}
}
return -1;
}
int main(){
int t, k;
cin >> t >> k;
for (register int i = 1; i <= t; i++){
int y, z, p;
cin >> y >> z >> p;
if (k == 1){
cout << quick_pow(y, z, p) << endl;
} else if (k == 2){
y %= p;
z %= p;
if (y == 0 && z != 0){
cout << "Orz, I cannot find x!" << endl;
} else {
cout << z * quick_pow(y, p - 2, p) % p << endl;
}
} else {
ll ans = bsgs(y, z, p);
if (ans == -1){
cout << "Orz, I cannot find x!" << endl;
} else {
cout << ans << endl;
}
}
}
return 0;
}
```
by Leasier @ 2020-03-19 16:04:49
@[limaopipi2022](/user/160839)
%%%$\Huge{\text{AK}}$ $\Huge{\text{IOI}}$の$\lmpy$大佬
by mazihang2022 @ 2020-03-19 16:05:35
我过了
这该死的特判
by Prean @ 2020-03-19 16:05:37
@[limaopipi2022](/user/160839)
%%%${\Huge{\text{\color{red}秒切\color{purple}紫题}}}$の$\lmpy$大佬
by mazihang2022 @ 2020-03-19 16:09:16