T =int(input())for i in range(T): n = input() a = [i for i in n]#将字符串的每一位存入数组中 b = [0 for i in range(5)] b[0] = a[0];b[1]=a[2];b[2]=a[4];b[3]=a[3];b[4]=a[1] b = int("".join(b)) b = str(pow(b,5))#计算5次方并转为字符串 ans = b[-5:]#截取倒a数第5到末尾的字符串 print("case #{}:".format(i)) print(ans)
#include<iostream>#include<string>usingnamespacestd;usingll=longlong;#define mod 100000;intmain(){stringp{};intn{};cin>>n;for(inti=0;i<n&&cin>>p;i++){llm{};m=m*10+p[0]-'0';m=m*10+p[2]-'0';m=m*10+p[4]-'0';m=m*10+p[3]-'0';m=m*10+p[1]-'0';llp=1;for(intj=0;j<5;j++){p=(p*m)%mod;}cout<<"case #"<<i<<':'<<endl;if(p<10000&&p>=1000)cout<<'0'<<p<<endl;elseif(p<1000&&p>=100)cout<<"00"<<p<<endl;elseif(p<100&&p>=10)cout<<"000"<<p<<endl;elseif(p<10&&p>=1)cout<<"0000"<<p<<endl;elseif(p==0)cout<<"00000"<<endl;elsecout<<p<<endl;}}
python处理大数还是很牛逼的:
注意开long long 99999平方可能会超max_int
include
using namespace std;
const int Go[5]={0,2,4,3,1};
int T;
string strs;
void alter()
{
string tmp;
for(int i=0;i<5;i++) tmp+=strs[Go[i]];
strs=tmp;
return;
}
void solve()
{
cin>>strs;
alter();
int xx;
stringstream ss(strs);
ss>>xx;
long long now=xx;
for(int i=1;i<5;i++) now=(now*xx)%100000;
printf(“%05lld\n”,now);
return;
}
int main()
{
scanf(“%d”,&T);
for(int step=0;step<T;step++)
{
printf(“case #%d:\n”,step);
solve();
}
return 0;
}
把%05d给忘了,搞了半天补0的方法(