输入只有5位,所以转化为long long类型用快速幂取模
前面补0的写法printf("%05lld ",ans);如果ans不足5位会在前面补0
1 #include<bits/stdc++.h> 2 using namespace std; 3 long long mod_exp(long long a, long long b, long long c) //快速幂取余a^b%c 4 { 5 long long res, t; 6 res = 1 % c; 7 t = a % c; 8 while (b) 9 { 10 if (b & 1) 11 { 12 res = res * t % c; 13 } 14 t = t * t % c; 15 b >>= 1; 16 } 17 return res; 18 } 19 int main() 20 { 21 int t; 22 while(~scanf("%d",&t)) 23 { 24 int cases=-1; 25 while(t--) 26 { 27 cases++; 28 char s[10],s2[10]; 29 scanf("%s",s); 30 s2[0]=s[0]; 31 s2[1]=s[2]; 32 s2[2]=s[4]; 33 s2[3]=s[3]; 34 s2[4]=s[1]; 35 long long temp=(s2[0]-'1'+1)*10000+(s2[1]-'1'+1)*1000+(s2[2]-'1'+1)*100+(s2[3]-'1'+1)*10+(s2[4]-'1'+1)*1; 36 printf("case #%d: %05lld ",cases,mod_exp(temp,5,100000)); 37 } 38 } 39 return 0; 40 }