2 1 6 2 9
9 81
/*------------------Header Files------------------*/ #include <iostream> #include <cstring> #include <string> #include <cstdio> #include <algorithm> #include <cstdlib> #include <ctype.h> #include <cmath> #include <stack> #include <queue> #include <deque> #include <map> #include <vector> #include <set> #include <limits.h> using namespace std; /*------------------Definitions-------------------*/ #define LL long long #define uLL unsigned long long #define PI acos(-1.0) #define INF 0x3F3F3F3F #define MOD 1000000007 #define MAX 105 #define lson rt<<1,l,m #define rson rt<<1|1,m+1,r /*---------------------Work-----------------------*/ set<LL>st; set<LL>::iterator it; //set迭代器 void work() { int T; cin>>T; while(T--) { st.clear(); int n; LL x; scanf("%d%I64d",&n,&x); LL Max=x; while((it=st.find(x))==st.end()) //判断当前x是否是当前最大且已经出现过 { st.insert(x); x=x*x; int cnt=0; LL temp=x; while(temp!=0) { temp=temp/10; cnt++; } if(cnt>n) x=x/pow(10,cnt-n); Max=max(Max,x); } printf("%I64d\n",Max); } } /*------------------Main Function------------------*/ int main() { //freopen("test.txt","r",stdin); work(); return 0; }