Topic Link: Click to open the link
Test instructions
Enter n K, which means the calculator can display n digits, initially with a number k
Each operation K = k^2, if the n bit is exceeded, the first n bits are intercepted.
The maximum number to be obtained.
Ideas:
First, we can tell that there must be a loop in this operation.
So how to terminate the loop, using the Floyd method
Let two loops child1 and child2 just start to be K, then child1 each time transformation, child2 each transformation 2 times;
This means that when child1 again equals child2, it is already at least a cyclic section, because Child2 has caught child1 from behind.
Import Java.io.printwriter;import java.util.arraylist;import Java.util.arrays;import Java.util.Collections;import Java.util.comparator;import Java.util.iterator;import Java.util.linkedlist;import Java.util.PriorityQueue;import Java.util.scanner;import Java.util.treeset;import Java.util.queue;public class Main {static int N = 100100;long N, K, MAXN Um;long work (long x) {x = X*x;while (x>=maxnum) x/= 10;return x;} void work () {int T = Cin.nextint (), while (t--> 0) {n = Cin.nextlong (); k = Cin.nextlong (); maxnum = 1;for (int i = 0; I < ; N i++) Maxnum *= 10;long ans = k;long a = k, b = k;do{a = Work (a); b = Work (b); ans = max (ans, b); b = Work (b); ans = max (ans, b);} while (a!=b); out.println (ANS);}} Main () {cin = new Scanner (system.in); out = new PrintWriter (System.out);} public static void Main (string[] args) {main E = new main (); E.work (); Out.close ();} Public Scanner cin;public static PrintWriter out;int upper_bound (int[] A, int l, int r, int val) {//upper_bound (a+l,a+r,val )-a;int pos = r;r--; WHILe (l <= R) {int mid = (l+r) >>1;if (a[mid]<=val) {L = mid+1;} else {pos = Mid;r = Mid-1;}} return POS;} /*class Queue {int[] queue = new Int[n+10];int front, rear;//front <= rearqueue () {//queue = new int[x];} void Clear () {front = rear = 1;} Boolean empty () {return front = = rear;} int size () {return rear-front;} int Front () {return queue[front];} int rear () {return queue[rear-1];} void push_rear (int x) {queue[rear++] = x;} void Pop_front () {front++;} void Pop_rear () {rear--;}} /**/int max (int x, int y) {return x > y x:y;} int min (int x, int y) {return x < y x:y;} Double Max (double x, double y) {return x > y x:y;} Double min (double x, double y) {return x < y x:y;} Long Max (long x, long y) {return x > y x:y;} Long min (long x, long y) {return x < y x:y;} static double EPS = 1e-8;int abs (int x) {return x > 0 ×:-X;} Double abs (double x) {return x > 0 ×:-X;} Boolean zero (double x) {return abs (x) < EPS;}}
UVA 11549 Calculator conundrum Floyd award ring