zcs2012 @ 2023-12-17 08:43:44
求助#3、#1不过
#include<cstdio>
#include<cctype>
#include<cstdlib>
#include<cstring>
int main(){
char m[70];
int n;
scanf("%d%s",&n,m);
for(int i=0;i<=30;i++){
char x[70];
for(int p=strlen(m),k=p;p--;)
x[p]=m[k-p-1];
if(!strcmp(m,x))
printf("STEP=%d\n",i),exit(0);
char y[70]={};
int p1=strlen(m);
memset(y,48,p1+1);
for(;p1--;){
int a=isdigit(m[p1])?m[p1]-48:m[p1]-55,b=isdigit(x[p1])?x[p1]-48:x[p1]-55;
// printf("%d %d ",a,b);
if((y[p1+1]+=(a+b)%n)>57)y[p1+1]+=7;
// printf("%d\n",y[p1+1]);
if(a+b>=n)y[p1]++;
}
strcpy(m,y[0]==48?y+1:y);
// puts(m);
// putchar('\n');
}
puts("Impossible!");
return 0;
}
by luoguandy @ 2023-12-17 08:59:39
#include<bits/stdc++.h>
using namespace std;
int n1[205],n2[205],step,base;
char c[105];
void add(){
for(int i=1;i<=200;i++){
n1[i]+=n2[i];
}
for(int i=1;i<=199;i++){
n1[i+1]+=n1[i]/base;
n1[i]%=base;
}
}
int len(int x[]){
int t;
for(int i=200;x[i]==0;i--)t=i;
return t-1;
}
void wrap(){
int len1=len(n1);
for(int i=len1;i>=1;i--){
n2[i]=n1[len1-i+1];
}
}
bool check(int x[]){
for(int i=1;i<=len(x)/2+1;i++){
if(x[i]!=x[len(x)-i+1])return 0;
}
return 1;
}
int main(){
cin>>base>>c;
for(int i=1;i<=strlen(c);i++){
if(c[strlen(c)-i]<='9')n1[i]=c[strlen(c)-i]-'0';
else if(c[strlen(c)-i]>='A'&&c[strlen(c)-i]<='Z')n1[i]=c[strlen(c)-i]-'A'+10;
else n1[i]=c[strlen(c)-i]-'a'+10;
}
for(;step<=30;step++){
wrap();
add();
if(check(n1)){cout<<"STEP="<<step+1;return 0;}
}
cout<<"Impossible!";
return 0;
}