春晚魔术[蓝桥]

这里

N=1,2,3..., ans=(ABC)^{2^N}

考虑到N很大则快速幂无法处理2^N,因为它并没有被取模

欧拉定理:

p是质数时

a^{p-1}\equiv 1\mod p

p=1e9+7是质数

(ABC)^{2^N}=(ABC)^{(1e9+6)}*(ABC)^{(1e9+6)}*...*(ABC)^{2^N\mod(1e9+6)}

两边同时取mod,a^{1e9+6}\equiv 1\mod 1e9+7

 (ABC)^{2^N}\mod 1e9+7=(ABC)^{2^N\mod 1e9+6}\mod 1e9+7

//
// Created by yumo_
//
#include<bits/stdc++.h>

using namespace std;
#define scin std::cin
#define scout std::cout
using i64=long long;
const int INF=INT_MAX/2;
const i64 INFF=LLONG_MAX/2;
const i64 md=1e9+7;
const int M=1e5+7;
int main() {

    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int T;
    scin>>T;
    // T=1;
    for (;T>0;--T) {
        i64 A,B,C;scin>>A>>B>>C;
        auto pow=[&](i64 a,i64 b,i64 Md) {
            i64 res=1;
            while (b>0) {
                if (b&1) res=res*a%Md;
                a=a*a%Md;
                b>>=1;
            }
            return res;
        };

        i64 N;scin>>N;N=pow(2,N,md-1);

        i64 ans=pow(A,N,md)*pow(B,N,md);ans%=md;
        ans=ans*pow(C,N,md);ans=ans%md;
        scout<<ans<<"\n";
    }

// 18 22 24
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值