iven a pair ofpositive integers, for example, 6 and 110, can this equation 6 = 110 be true?The answer is "yes", if 6 is a decimal number and 110 is a binarynumber.

Now for any pair ofpositive integers N1 and N2, your task is to find the radix of one number whilethat of the other is given.

InputSpecification:

Each input filecontains one test case. Each case occupies a line which contains 4 positiveintegers:
Here N1 and N2 each has no more than 10 digits. A digit is less than its radixand is chosen from the set {0-9, a-z} where 0-9 represent the decimal numbers0-9, and a-z represent the decimal numbers 10-35. The last number"radix" is the radix of N1 if "tag" is 1, or of N2 if"tag" is 2.

OutputSpecification:

For each test case,print in one line the radix of the other number so that the equation N1 = N2 istrue. If the equation is impossible, print "Impossible". If thesolution is not unique, output the smallest possible radix.

SampleInput 1:

6 110 1 10

SampleOutput 1:

2

SampleInput 2:

1 ab 1 2

SampleOutput 2:

Impossible

1010.基数

#include<cstdio>
char N1[11]="\0",N2[11]="\0";
long long calValue(char N[],long long radix);
long long judge(long long n1,char N[],int minrad);
int main()
{
long long n1,n2;
long long out;
scanf("%s",N1);
scanf("%s",N2);
scanf("%lld",&tag);
if(tag==1)
{
if(n1<0)
out=0;
else
}else
{
if(n2<0)
out=0;
else
}
if(out==0)
printf("Impossible\n");
else
printf("%lld\n",out);
return 0;
}
long long calValue(char N[],long long radix)
{
long long sum=0;
long long i=0;
while(N[i]!='\0')
{
if(N[i]>='0'&& N[i]<='9')
else
if(sum<0)
return -1;
i++;
}
return sum;
}
{
int i,Max=0;
for(i=0;N[i]!=0;i++)
if(N[i]>Max)
Max=N[i];
if(Max>='0'&& Max<='9')
return Max-'0';
else
return Max-'a'+10;
}
long long judge(long long n1,char N[],int minrad)
{
unsigned long long n2;
if(beg>end)
end=beg;
unsigned long long mid=(beg+end)/2;
while(mid>=beg && mid<=end)
{
n2=calValue(N,mid);
if(n2<0)
return 0;
if(n2==0 && n2==n1)
return 1;
if(n1==n2)
return mid;
if(n2>n1)
end=mid-1;
else
beg=mid+1;
mid=(beg+end)/2;
}
return 0;
}


6 110 1 10

2

1 ab 1 2

Impossible