记录编号 157829 评测结果 AAAAAAAAAAA
题目名称 [USACO Jan15] 所有进制 最终得分 100
用户昵称 Gravatarslyrabbit 是否通过 通过
代码语言 C++ 运行时间 0.132 s
提交时间 2015-04-10 20:00:27 内存使用 0.54 MiB
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n;
long long x[15001]={0};
long long y[15001]={0};
long long work(int a,int p)
{
	long long ans=0;
	long long base=1;
	while(a>0)
	{
		ans+=(a%10)*base;
		a/=10;
		base*=p;
	}
	return ans;
}
int main()
{
	freopen("whatbase.in","r",stdin);
	freopen("whatbase.out","w",stdout);
	cin>>n;
	int x1,y1;
	while(n--)
	{
		cin>>x1>>y1;
		long long X,Y;
		for(int i=11,j=11;i<=15000,j<=15000;)
		{
			if(x[i])
				X=x[i];
			else
			{
			    X=work(x1,i);
				x[i]=X;
			}
			if(y[j])
				Y=y[j];
			else
			{
				Y=work(y1,j);
				y[j]=Y;
			}
			if(X==Y)
			{
				cout<<i<<" "<<j<<endl;
				goto out;
			}
			if(Y>X) i++;
			else j++;
		}
		out:;
		memset(x,0,sizeof(x));
		memset(y,0,sizeof(y));
	}
	return 0;
}