AC 0%(样例过了)
#include <bits/stdc++.h>
using namespace std;
string a, b;
void rev(){
for (int i = a.size() - 1; i >= 0; i--)
b.push_back(a[i]);
}
void add(int base){
int t = 0;
for (int i = a.size() - 1; i >= 0; i--){
int p = a[i] + b[i] + t;
a[i] = (p % base);
t = p / base;
}
}
bool check(){
for (int i = 0; i < a.size() / 2; i++)
if (a[i] != a[a.size() - 1 - i])
return false;
return true;
}
void huiwen(int base){
for (int i = 1; i <= 30; i++){
if (check()){
cout << "STEP=" << (i - 1);
return ;
}
rev();
add(base);
while (a[0] == '0')
a = a.substr(1);
}
cout << "Impossible!";
}
int main(){
int base;
string s;
cin >> base >> s;
for (int i = 0; i < s.size(); i++){
if (s[i] >= '0' && s[i] <= '9')
a += s[i] - '0';
if (s[i] >= 'A' && s[i] <= 'Z')
a += s[i] - 'A' + 10;
}
huiwen(base);
return 0;
}