Topic link
Direct simulation of the calculation process. You can see that the calculator shows the number is circular, the key lies in the simulation process, how to determine whether the cycle.
You can use the map or set in STL, but the efficiency is low. Hash words consume a lot of space.
You can tell from the big white that there is also a kind of thing called "Floyd Circle Method". It's fake. There are two children running on a circle track and starting at the same time, but one child is twice times faster than the other, so the fast-running child will "catch up" with the slow-running child (more than n laps). When more than that moment, to be sure, this time the fast child has at least 1 laps, that is, "after a cycle." So as long as the simulation track record fast.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <set>
using namespace std;
typedef long long Int64;
Char buf[12];
Int64 GetNext (int n, int64 k) {
Int64 now = (Int64) k*k;
int len = 0;
Int64 tmp = now;
while (tmp>0) {++len. tmp/=}
while (Len-n > 0) {--len. Now/=}
return to now;
}
int main () {
int ncase, n;
Int64 K;
scanf ("%d", &ncase);
while (ncase--) {
cin >> n >> K;
Int64 ans = k;
Int64 slow=k, fast=k;
do{
slow = GetNext (n, slow);
Fast = GetNext (n, fast); ans = max (ans, fast);
Fast = GetNext (n, fast); Ans = max (ans, fast); while
(slow!= fast);
cout << ans << endl;
return 0;
}
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/