#include <iostream> #include <cstdio> #include <cstring> #include <cmath> using namespace std; int GetRemainder(int baseNum, int power, int modelNum) { //判断各个值正确性 baseNum %= modelNum; power %= (modelNum - 1);//小费马定理 int tempNum = 1; int remainder = 0; while (power >= 1) { //当为1的时候,得出结果 if (power == 1) { remainder = (tempNum * baseNum) % modelNum; break; } else { //如果指数是偶数,将基数平方,指数除以2 if ((power&1)==0) { baseNum = (baseNum * baseNum) % modelNum; power>>=1; } //如果是奇数,将tempNum乘以基数 并取模,指数减1 else { tempNum = (tempNum*baseNum)%modelNum; power -= 1; } } } return remainder; } long ppp[3]; int main() { int g[3] = {2,3,167}; int op[3] = {1,15,18}; int ans,y; long x; while(scanf("%ld",&x) != EOF ) { ppp[0] = 2 * x; ppp[1] = 1 * x; ppp[2] = 1 * x; ans = 1; y = GetRemainder(2,ppp[0]+1,29); y = y - 1; y = y * op[0]; ans *= y; y = GetRemainder(3,ppp[1]+1,29); y = y - 1; y = (y * op[1]) % 29; ans *= y; y = GetRemainder(167,ppp[2]+1,29); y = y - 1; y = (y * op[2]) % 29; ans *= y; ans = ans % 29; printf("%d\n",ans); } return 0; }
本文出自 “Qero” 博客,请务必保留此出处http://8590696.blog.51cto.com/8580696/1358916
原文:http://8590696.blog.51cto.com/8580696/1358916