KiloCranes @ 2024-01-07 20:37:26
#include <bits/stdc++.h>
using namespace std;
const int N=1000;
int n,l,step;
char s[N];
int t[N],t1[N],t2[N];
int main(){
cin>>n;
cin>>s;
l=strlen(s);
for(int i=0;i<l;i++)
if(s[i]=='A')
t[i]=11;
else if(s[i]=='B')
t[i]=12;
else if(s[i]=='C')
t[i]=13;
else if(s[i]=='D')
t[i]=14;
else if(s[i]=='E')
t[i]=15;
else if(s[i]=='F')
t[i]=16;
else
t[i]=s[i]-'0';
while(step<=30){
step++;
memset(t1,0,sizeof(t1));
memset(t2,0,sizeof(t2));
for(int i=0;i<l;i++){
t1[i]=t[i];
t2[i]=t[l-i-1];
}
memset(t,0,sizeof(t));
for(int i=0;i<l;i++){
t[i]+=t1[i]+t2[i];
if(t[i]>=n)
while(t[i]>=n){
t[i]-=n;
t[i+1]++;
}
}
int check=1;
l++;
if(t[l-1]==0)
l--;
for(int i=0;i<l;i++)
if(t[i]!=t[l-i-1]){
check=0;
break;
}
if(check)
break;
}
if(step<=30){
cout<<"STEP=";
cout<<step;
}else
cout<<"Impossible!";
return 0;
}
by DGL__DGL_AFO @ 2024-01-12 20:41:52
A=10
B=11
C=12
D=13
E=14
F=15
by DGL__DGL_AFO @ 2024-01-12 20:42:11
@KiloCranes
by MoonRises @ 2024-01-31 09:25:04
建议看一下16进制的知识