借鉴http://blog.sina.com.cn/s/blog_8619a25801010wcy.html
题目地址:http://ac.jobdu.com/problem.php?pid=1085
//九度OJ 快速取模之《root(n,k)》 //http://ac.jobdu.com/problem.php?pid=1085 #include<stdio.h> int k; long fang(long a,long b) { long long ret=1; while(b) { if(b&1)ret=ret*a%(k-1); a=a*a%(k-1); b>>=1; } return ret; } int main() { long long x,y; int i; while(~scanf("%lld %lld %d",&x,&y,&k)) { long ret=fang(x,y); if(!ret)ret=k-1; printf("%lld\n",ret); } return 0; }
作者:xln0539xln 发表于2013-2-23 8:27:23 原文链接
阅读:0 评论:0 查看评论