题解 | #用来作弊的药水#

用来作弊的药水

https://ac.nowcoder.com/acm/problem/15324

考察知识点:快速幂

题目很长,但是意思很简单,就是判断 xax^ayby^b 是否相等。

使用快速幂优化即可。

时间复杂度O(loga+logb)O(\log a+\log b)

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

ll qpw(ll a, ll b, ll mod = 1e9 + 7)
{
    ll res = 1;
    while (b)
    {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod, b >>= 1;
    }
    return res;
}

void solve()
{
    ll x, a, y, b;
    cin >> x >> a >> y >> b;
    if (qpw(x, a) == qpw(y, b))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
    cin >> t;
    while (t--)
        solve();
    return 0;
}
全部评论

相关推荐

评论
2
收藏
分享

创作者周榜

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