#include<bits/stdc++.h>
using namespace std;
main()
{
long long n,m;
string s;
while(cin>>n>>m>>s)
{
long long i,k=0,sum=0,pow1=0,flag=0,k1=0,k2=0;
string ar;
if(s[0]=='0')
printf("0 base %lld = 0 base %lld\n",n,m);
else
{
pow1=0;
long l=s.size();
for(i=l-1;i>=0;i--)
{
if(s[i]>='0'&&s[i]<='9')
k=s[i]-48;
else
k=s[i]-55;
if(k>=n)
flag=1;
sum=sum+(k*(pow(n,pow1++)+.00000000000001));
}
k1=0;
if(sum==0)
ar[0]=0;
while(sum!=0)
{
k2=sum%m;
if(k2>9)
{
ar[k1]=char(k2+55);
}
else
ar[k1]=char (k2+48);
sum/=m;
k1++;
}
if(flag==1)
cout<<s<<" is an illegal base "<<n<<" number"<<endl;
else
{
cout<<s;
printf(" base %lld = ",n);
for(i=k1-1;i>=0;i--)
{
cout<<ar[i];
}
printf(" base %lld\n",m);
}
}
}
}
কোন মন্তব্য নেই:
একটি মন্তব্য পোস্ট করুন