//====================================================================||
// ||
// ||
// Author : GCA ||
// 6AE7EE02212D47DAD26C32C0FE829006 ||
//====================================================================||
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cctype>
#include <utility>
using namespace std;
#ifdef ONLINE_JUDGE
#define ll "%lld"
#else
#define ll "%I64d"
#endif
typedef unsigned int uint;
typedef long long int Int;
#define Set(a,s) memset(a,s,sizeof(a))
#define Write(w) freopen(w,"w",stdout)
#define Read(r) freopen(r,"r",stdin)
#define Pln() printf("\n")
#define I_de(x,n)for(int i=0;i<n;i++)printf("%d ",x[i]);Pln()
#define De(x)printf(#x"%d\n",x)
#define For(i,x)for(int i=0;i<x;i++)
#define CON(x,y) x##y
#define Pmz(dp,nx,ny)for(int hty=0;hty<ny;hty++){for(int htx=0;htx<nx;htx++){\
printf("%d ",dp[htx][hty]);}Pln();}
#define M 2000
#define PII pair<int,int>
#define PB push_back
#define oo INT_MAX
#define Set_oo 0x3f
#define Is_debug true
#define debug(...) if(Is_debug)printf("DEBUG: "),printf(__VA_ARGS__)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define eps 1e-6
bool xdy(double x,double y){return x>y+eps;}
bool xddy(double x,double y){return x>y-eps;}
bool xcy(double x,double y){return x<y-eps;}
bool xcdy(double x,double y){return x<y+eps;}
int min3(int x,int y,int z){
int tmp=min(x,y);
return min(tmp,z);
}
int max3(int x,int y,int z){
int tmp=max(x,y);
return max(tmp,z);
}
char str[M];
char str2[M];
void add(char a[],char ans[],int b){
int n=strlen(a);
int c=0;
for(int i=0;i<n;i++){
if(a[i]>='A')a[i]=a[i]-'A'+10;
else a[i]-='0';
}
for(int i=0;i<n;i++){
int tmp=a[i]+a[n-i-1]+c;
c=tmp/b;
ans[i]=tmp%b;
if(ans[i]==10)ans[i]='A';
else if(ans[i]==11)ans[i]='B';
else if(ans[i]==12)ans[i]='C';
else if(ans[i]==13)ans[i]='D';
else if(ans[i]==14)ans[i]='E';
else ans[i]+='0';
}
ans[n]='';
if(c){
ans[n]='0'+c;
ans[n+1]='';
}
}
bool check(char a[]){
int n=strlen(a);
for(int i=0;i<n;i++){
if(a[i]!=a[n-i-1])return false;
}
return true;
}
bool over(char a[],int b){
char c[M];
strcpy(c,a);
int n=strlen(c);
for(int i=0;i<n;i++){
if(c[i]=='A')c[i]=10;
else if(c[i]=='B')c[i]=11;
else if(c[i]=='C')c[i]=12;
else if(c[i]=='D')c[i]=13;
else if(c[i]=='E')c[i]=14;
else c[i]-='0';
if(c[i]>=b)return true;
}
return false;
}
int main() {
ios_base::sync_with_stdio(0);
int ans[16];
char ostr[M];
while(~scanf("%s",str)){
strcpy(ostr,str);
for(int i=0;i<16;i++)ans[i]=-1;
for(int i=15;i>=2;i--){
if(over(ostr,i))break;
strcpy(str,ostr);
int cnt;
for(cnt=0;;cnt++){
if(check(str))break;
add(str,str2,i);
// puts(str2);
strcpy(str,str2);
}//puts("");
ans[i]=cnt;
}
for(int i=15;i>2;i--){
if(ans[i]!=-1)printf("%d ",ans[i]);
else printf("? ");
}
if(ans[2]!=-1)printf("%d\n",ans[2]);
else printf("?\n");
}
}
留言
張貼留言