题解 | #华华教月月做数学#

华华教月月做数学

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

思路

这道题大家都在用快速乘,我用int128就过了。
记得要重载输入输出,然后加个快速幂就好了。

代码

#include<bits/stdc++.h>
#define int __int128
using namespace std;
typedef long long ll;

int fpow(int a,int b,int p){
    int res=1;
    while(b){
        if(b&1) res=res*a%p;
        a=a*a%p;
        b>>=1;
    }
    return res%p;
}

inline void read(int &data){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    data=x*f;
}

void write(int x){
    if(x>9) write(x/10);
    putchar(x%10+'0');
}

signed main(){
    int t,a,b,p;
    read(t);
    while(t--){
        read(a);read(b);read(p);
        write(fpow(a,b,p));
        printf("\n");
    }
    return 0;
}
全部评论

相关推荐

仁者伍敌:牛子这些人还会点一个自动回复,boss都不带回复的
点赞 评论 收藏
分享
06-23 11:28
门头沟学院 Java
牛客91966197...:也有可能是点拒绝的时候自动弹的话术
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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