[2020牛客寒假算法基础集训营2]G-判正误

不得不说的是我觉得这道题十分的奇怪。

取模数这么随便。我怀疑它没有很强的数据。

先说说做法吧。就是简单的快速幂取模即可。(但是这个取模也太玄学了吧。出题人自己都说多尝试几次,我吐了

#include <bits/stdc++.h>
#define speed std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;
typedef long long ll;

const ll maxn = 200005;
const ll mod = 1e9+7;
ll a,b,c,d,e,f,g;
ll ans=0;
ll qpow(ll a, ll b){
    ll ret = 1;
    while(b){
        if(b & 1) ret = (ret * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return ret;
}

int main()
{
    speed;
    ll T;
    cin>>T;
    while(T--){
        cin>>a>>b>>c>>d>>e>>f>>g;
        ll tmp=(qpow(a,d)+qpow(b,e)+qpow(c,f));
        if(tmp==g){
            cout<<"Yes\n";
        }
        else{
            cout<<"No\n";
        }
    }
}

猜你喜欢

转载自www.cnblogs.com/Vikyanite/p/12288340.html
今日推荐