题目:
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=27&page=show_problem&problem=2544
分析:Floyd判圈算法
代码:
#include <cstdio>
#include <algorithm>
#include <math.h>
using namespace std;
int n,k;
long long int ans,MOD;
void work()
{
long long int t1=k,t2=k;
ans=k;MOD=pow(10,n);
do{
t1*=t1;
while((t1/MOD)>0) t1/=10;
ans=max(ans,t1);
t2*=t2;
while((t2)/MOD>0) t2/=10;
ans=max(ans,t2);
t2*=t2;
while((t2)/MOD>0) t2/=10;
ans=max(ans,t2);
}while(t1!=t2);
return;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d %d",&n,&k);
work();
printf("%lld\n",ans);
}
return 0;
}