Advertisement
erfanul007

UVa 11549

Jul 27th, 2019
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef unsigned long long int ull;
  5. typedef long long int ll;
  6. typedef vector<int> vi;
  7. typedef vector<ll> vll;
  8. typedef vector<vi> vvi;
  9. typedef pair<int,int > pii;
  10. typedef vector< pii > vpii;
  11. typedef set<int> sti;
  12.  
  13. #define sc scanf
  14. #define pf printf
  15. #define sci(n) scanf("%d",&n)
  16. #define scii(n,m) scanf("%d %d",&n,&m)
  17. #define scl(n) scanf("%lld",&n)
  18. #define scd(n) scanf("%lf",&n)
  19. #define scs(s) scanf("%s",s)
  20. #define pfi(n) printf("%d",n)
  21. #define pfl(n) printf("%lld",n)
  22. #define pff(n) cout<<n
  23. #define line printf("\n")
  24. #define spc printf(" ")
  25. #define loop(i,x,y) for(int i=int(x); i<=int(y); i++)
  26. #define rloop(i,y,x) for(int i=int(y); i>=int(x); i--)
  27. #define cspf(i) printf("Case %d: ", i)
  28. #define vout(v) for(int w=0;w<v.size();w++){if(w) cout<<' '; cout<<v[w];}
  29. #define pb push_back
  30. #define mp make_pair
  31. #define ff first
  32. #define ss second
  33. #define all(v) v.begin(),v.end()
  34. #define rall(v) v.rbegin(),v.rend()
  35. #define read() freopen("input.txt", "r", stdin)
  36. #define write() freopen("output.txt", "w", stdout)
  37. #define fastIO() ios_base::sync_with_stdio(false); cin.tie(NULL);
  38. /// Constants
  39. #define eps 1e-9
  40. #define PI acos(-1.0) // 3.1415926535897932
  41. #define MAX 1000009
  42.  
  43. int digitcount(ll x,int cnt)
  44. {
  45. if(x==0) return cnt;
  46. return digitcount(x/10,cnt+1);
  47. }
  48.  
  49. ll SQR(ll x)
  50. {
  51. return x*x;
  52. }
  53.  
  54. int main()
  55. {
  56. //read();
  57. //write();
  58. ll ten[20],k=1;
  59. loop(i,0,18){
  60. ten[i]=k;
  61. k*=10;
  62. }
  63. int t;
  64. sci(t);
  65. while(t--){
  66. int n;
  67. ll x;
  68. sci(n);
  69. scl(x);
  70. ll mx = x;
  71. map < ll, bool > flg;
  72. while(1){
  73. if(flg[x]) break;
  74. flg[x]=1;
  75. x = SQR(x);
  76. int d = digitcount(x,0);
  77. if(d>n){
  78. x = x/ten[d-n];
  79. }
  80. mx = max(x,mx);
  81. }
  82. pfl(mx);line;
  83. }
  84. return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement