九度OJ 二分求幂法、快速取模之《root(n,k)》
[cpp]//九度OJ 快速取模之《root(n,k)》//http://ac.jobdu.com/problem.php?pid=1085#include<stdio.h>int k; www.zzzyk.comlong 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;}
补充:软件开发 , C++ ,