题解 | #求root(N, k)#

求root(N, k)

http://www.nowcoder.com/practice/9324a1458c564c4b9c4bfc3867a2aa66

#include<iostream>

using namespace std;

long root(long x,long y,int k){
    int result=1;
    while(y!=0){
        if(y%2==1){
            result *= x;
            result %= k;
        }
        x *= x;
        x %=k;
        y/=2;
    }
    return result;
}

int main(){
    int x,y,k;
    while(cin>>x>>y>>k){
        int result=root(x,y,k-1);
        if(result==0){
            result = k-1;
        }
        cout<<result;
    }
    return 0;
}
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-11 11:21
被夸真的超级开心,好可爱的姐姐
码农索隆:老色批们不用脑补了,我把金智妮的图找来了查看图片
点赞 评论 收藏
分享
06-23 11:43
门头沟学院 Java
allin校招的烤冷...:我靠,今天中午我也是这个hr隔一个星期发消息给我。问的问题还是一模一样的😅
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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