题目链接:http://bailian.openjudge.cn/practice/2972
#include<stdio.h>
int Y(int i,int B)
{
int f=1;
while(i>0)
{f=B*f;i--;}
return f;
}
int G(int x,int B)
{
int sum=0,i=0,t;
while(x!=0)
{
t=x%10;
if(t>=B)
return 2;
sum=sum+t*Y(i,B);
i++;
x=x/10;
}
return sum;
}
int F(int a,int b,int c)
{
int B;
for(B=2;B<=16;B++)
{
if((G(a,B)*G(b,B))==G(c,B))
return B;
}
return 0;
}
int main()
{
int i,n,a,b,c;
scanf("%d",&n);
getchar();
for(i=1;i<=n;i++)
{
scanf("%d%d%d",&a,&b,&c);
printf("%d\n",F(a,b,c));
}
return 0;
}