判正误

判正误

http://www.nowcoder.com/questionTerminal/327a56cada244fc79c7d61936624989c

判正误
https://ac.nowcoder.com/acm/contest/3003/G
图片说明

考察快速幂求余
g<=1e9,可考虑mod=1e9+7
在左边三项求幂运算中,对其进行快速幂同时mod即可

#pragma warning (disable :4996)
#include <iostream>
#include <cstdio>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
ll mod = 1e9 + 7;
ll a, b, c, d, e, f, g;
ll quick(ll x, ll y) {
    ll res = 1;
    while (y) {
        if (y & 1) res = (res*x)%mod;
        x =(x* x)%mod;
        y = y >>= 1;
    }
    return res;
}
int main()
{
    int t;
    scanf("%d", &t);
    while (t--) {
        scanf("%lld %lld %lld %lld %lld %lld %lld", &a, &b, &c, &d, &e, &f, &g);
        ll x, y, z;
        x = quick(a, d)%mod;
        y = quick(b, e)%mod;
        z = quick(c, f)%mod;
        g = g % mod;
        if (x + y + z == g)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
}
全部评论

相关推荐

不愿透露姓名的神秘牛友
12-17 17:40
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务