Saleh127

UVA 11549

Mar 16th, 2021
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(0);
  8. cin.tie(0);cout.tie(0);
  9.  
  10. test
  11. {
  12. map<ll,ll>x;
  13.  
  14. ll n,m,i,j,k,l=0,num;
  15.  
  16. cin>>n>>k;
  17.  
  18. while(1)
  19. {
  20. string a=to_string(k);
  21. num=0;
  22. for(i=0;i<n && i<a.size();i++)
  23. {
  24. num=num*10+(a[i]-'0');
  25. }
  26. l=max(l,num);
  27. if(x[num]) break;
  28. x[num]=1;
  29. k=num*num;
  30. }
  31. cout<<l<<endl;
  32. }
  33.  
  34.  
  35. return 0;
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment