2020牛客寒假算法基础集训营2-G 判正误
题目链接:https://ac.nowcoder.com/acm/contest/3003/G
判断一个式子是不是成立。直接快速幂明显会爆,上取模快速幂,模数1e9+7;
这样就过了,也不知道为啥:
#include <iostream> #include <cstring> #include <queue> #include <algorithm> #include <cmath> #include <map> #include <set> #define il inline #define ll long long #define LL long long using namespace std; const int maxn = 1e5 + 10; const ll inf = 0x7ffffffffff; const ll mod = 1e9+7; template<class T> inline void read(T &res) { char c; T flag = 1; while ((c = getchar()) < '0' || c > '9')if (c == '-')flag = -1; res = c - '0'; while ((c = getchar()) >= '0' && c <= '9')res = res * 10 + c - '0'; res *= flag; } ll t; ll qpow(ll a,ll b){ ll ans=1;; a%=mod; while(b){ if(b&1) ans=(ans*a)%mod; a=(a*a)%mod; b>>=1; } return ans%mod; } int main() { ll n; cin>>t; while(t--){ ll a,b,c,d,e,f,g; cin>>a>>b>>c>>d>>e>>f>>g; if(qpow(a,d)+qpow(b,e)+qpow(c,f)==g){ cout<<"Yes"<<endl; } else cout<<"No"<<endl; } return 0; }