题意是说,输入整数n,1<=n<=10^1000,求66^n mod 100的余数。一看这类题目,肯定是找规律。计算了前12个数,规律就出现了:1,66,56,96,36,76,16,56,96,36,76,16……所以,计算这个余数就是仅仅跟n有关了。
C++在处理n时还比较麻烦,在这点上,python真的是太方便(虽然效率不高)
python版本AC代码
ans = [76,16,56,96,36]
testcase = int(input())
while testcase > 0:
testcase -= 1
n = int(input())
if n == 0:
print('1')
elif n == 1:
print('66')
else:
print(ans[n%5])
C++版本AC代码
#include <iostream>
#include<cstdio>
#include<cstring>
using namespace std;
//#define ZANGFONG
char n[1010];
int ans[6] = {76,16,56,96,36};
int main()
{
#ifdef ZANGFONG
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif // ZANGFONG
int testcase,i,res,len;
scanf("%d\n",&testcase);
while(testcase--)
{
memset(n,0,sizeof(n));
scanf("%s\n",n);
len = strlen(n);
res = n[0] - '0';
if(len == 1)
{
if(res == 0) printf("1\n");
else if(res == 1) printf("66\n");
else printf("%d\n",ans[res%5]);
}
else{
res = n[len-1] - '0';
res %= 5;
printf("%d\n",ans[res]);
}
}
return 0;
}