#include<bits/stdc++.h>
using namespace std;
main()
{
string s1,s2;
while(cin>>s1>>s2)
{
long long l1,l2,i1,i2,i,pow1=0,flag=0,flag1=0,k,sum1=0,sum2=0,f=0;
l1=s1.size();
l2=s2.size();
for(i1=2;i1<=36;i1++)
{
for(i2=2;i2<=36;i2++)
{
pow1=0;
flag=0,flag1=0;
sum1=0,sum2=0;
for(i=l1-1;i>=0;i--)
{
if(s1[i]>='0'&&s1[i]<='9')
{
k=s1[i]-48;
}
else
k=s1[i]-55;
if(k>=i1)
flag=1;
sum1=sum1+k*(pow(i1,pow1++)+.000000000001);
}
pow1=0;
for(i=l2-1;i>=0;i--)
{
if(s2[i]>='0'&&s2[i]<='9')
{
k=s2[i]-48;
}
else
k=s2[i]-55;
if(k>=i2)
flag=1;
sum2=sum2+k*(pow(i2,pow1++)+.000000000001);
}
if(flag==1)
continue;
if(sum1==sum2)
{
flag1=1;
break;
}
}
if(flag1==1)
{
break;
}
}
if(sum1==sum2)
{
cout<<s1;
printf(" (base %lld) = ",i1);
cout<<s2;
printf(" (base %lld)\n",i2);
}
else
{
cout<<s1;
printf(" is not equal to ");
cout<<s2;
printf(" in any base 2..36\n");
}
}
}
using namespace std;
main()
{
string s1,s2;
while(cin>>s1>>s2)
{
long long l1,l2,i1,i2,i,pow1=0,flag=0,flag1=0,k,sum1=0,sum2=0,f=0;
l1=s1.size();
l2=s2.size();
for(i1=2;i1<=36;i1++)
{
for(i2=2;i2<=36;i2++)
{
pow1=0;
flag=0,flag1=0;
sum1=0,sum2=0;
for(i=l1-1;i>=0;i--)
{
if(s1[i]>='0'&&s1[i]<='9')
{
k=s1[i]-48;
}
else
k=s1[i]-55;
if(k>=i1)
flag=1;
sum1=sum1+k*(pow(i1,pow1++)+.000000000001);
}
pow1=0;
for(i=l2-1;i>=0;i--)
{
if(s2[i]>='0'&&s2[i]<='9')
{
k=s2[i]-48;
}
else
k=s2[i]-55;
if(k>=i2)
flag=1;
sum2=sum2+k*(pow(i2,pow1++)+.000000000001);
}
if(flag==1)
continue;
if(sum1==sum2)
{
flag1=1;
break;
}
}
if(flag1==1)
{
break;
}
}
if(sum1==sum2)
{
cout<<s1;
printf(" (base %lld) = ",i1);
cout<<s2;
printf(" (base %lld)\n",i2);
}
else
{
cout<<s1;
printf(" is not equal to ");
cout<<s2;
printf(" in any base 2..36\n");
}
}
}
কোন মন্তব্য নেই:
একটি মন্তব্য পোস্ট করুন