yiyezhiqiu1011 @ 2023-10-05 10:14:56
#include<bits/stdc++.h>
using namespace std;
int alen,blen,n;
bool hui(int h[])
{
for (int i = 0; i < alen; i++)
{
if (h[i] != h[alen - i - 1])
return false;
}
return true;
}
int wei(int n1)
{
int cnt = 0;
while (n1)
{
cnt++;
n1 /= 10;
}
return cnt;
}
void jia(int a[],int b[])
{
int in = 0;
for (int i = 0; i < alen; i++)
{
a[i] += a[i] + in + b[i];
in = a[i] / n;
a[i] %= n;
}
if (in)
{
a[alen] = in;
alen++;
blen++;
}
for (int i = 0; i < blen; i++)
b[blen-1-i] = a[i];
}
int main()
{
int a[300]={},b[300]={},m;
cin >> n >> m;
alen = wei(m);
blen = alen;
for (int i = wei(m)-1; i >= 0; i--)
{
a[i] = n % 10;
b[blen-1-i] = a[i];
n /= 10;
}
for (int i = 1; i <= 30; i++)
{
jia(a,b);
if (hui(a))
{
cout << "STEP=" << i;
return 0;
}
}
cout << "Impossible!";
return 0;
}
by CHWe668 @ 2023-10-18 22:56:06
4是”Impossible!“。