Niu Ke—Potion for cheating
Title
It’s very simple to judge xax^{a}xa和 y b y^{b} YWhether b is equal. But according to the title, you will findxax^{a}xa is very large and needs to be modulo, but I am afraid that the data will be changed after the modulus and the two numbers are not equal. In fact, it is enough to take the modulus twice so that the judgment will not go wrong.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod1 = 1e9 + 7;
const ll mod2 = 1e9 + 9;
ll fastpow(ll a, ll n, ll k){
ll res = 1, base = a;
while(n){
if(n & 1)
res = (res * base) % k;
base = (base * base) % k;
n >>= 1;
}
return res;
}
int main(){
ll t;
cin >> t;
while(t--){
ll a, b, c, d;
cin >> a >> b >> c >> d;
ll x1, y1, x2, y2;
x1 = fastpow(a, b, mod1);
y1 = fastpow(c, d, mod1);
x2 = fastpow(a, b, mod2);
y2 = fastpow(c, d, mod2);
if(x1 == y1 && x2 == y2)
puts("Yes");
else
puts("No");
}
return 0;
}