HYCAO @ 2023-04-12 17:37:50
#include<bits/stdc++.h>
using namespace std;
int n,s=0;
string add(string a,string b)
{
string c;
int t,i,j,lena,lenb,x=0;
lena=a.size();
lenb=b.size();
for(i=0;i<lena/2;i++) swap(a[i],a[lena-i-1]);
for(i=0;i<lenb/2;i++) swap(b[i],b[lenb-i-1]);
for(i=0;i<lenb&&i<lena;i++)
{
t=a[i]-'0'+b[i]-'0'+x;
x=t/n;
c.push_back(t%n+'0');
}
while(i<lena)
{
t=a[i++]-'0'+x;
x=t/n;
c.push_back(t%n+'0');
}
while(i<lenb)
{
t=b[i++]-'0'+x;
x=t/n;
c.push_back(t%n+'0');
}
if(x>0)
c.push_back(x+'0');
int len=c.size();
for(int i=0;i<len/2;i++)
{
swap(c[i],c[len-i-1]);
}
return c;
}
bool check(string a)
{
int len=a.size();
for(int i=0;i<len;i++)
{
if(a[i]!=a[len-i-1]) return 0;
}
return 1;
}
int main()
{
string a,b,c;
cin>>n>>a;
if(check(a)==0)
{
cout<<"STEP=0";
return 0;
}
int i=1;
while(i<=30)
{
s++;
reverse(a.begin(),a.end());
b=a;
reverse(a.begin(),a.end());
a=add(a,b);
if(check(a)==1)
{
printf("STEP=%d",s);
return 0;
}
++i;
}
cout<<"Impossible!";
return 0;
}
by HYCAO @ 2023-04-12 17:39:09
P1015
by _dhrxx_ @ 2023-04-12 19:17:23
看tj
by HYCAO @ 2023-04-12 21:45:57
@[Az_dream](/user/407994) 谢谢大佬