求 A^B mod C. (1<=A,C<=1000000000,1<=B<=10^1000000).(fzu1759,hdu3221,hdu4335)
题目: http://acm.fzu.edu.cn/problem.php?pid=1759 也算是快速幂的一题了,只不过这里的指数B特别大。需要用到一个公式: A^x = A^(x % Phi(C) + Phi(C)) (mod C),其中x≥Phi(C) 具体证明可见ac大神博客: http://hi.baidu.com/aekdycoin/item/e493adc9a7c0870bad092fd9 。数论学得各种败笔和急于求成,自己的理解就不谈了~直接上代码就是直接用到公式即可: 1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<algorithm> 5 #include<cstring> 6 using namespace std; 7 char bb[1000005]; 8 __int64 euler(__int64 x){ 9 __int64 i, res = x; 10 for(i=2;i<(__int64)sqrt(x*10)+1;i++){// 11 if(x%i==0){ 12 res = res /i *(i-1); 13 while(x%i==0) x/=i; 14 } 15 } 16 if(x>1) res = res/x*(x-1); 17 return res;