The ingenious method of this problem is not thought out, but it is an optimized brute force hack. Accepted
ImportJava.io.BufferedInputStream;ImportJava.util.Scanner; Public classMain { Public Static voidMain (string[] args) {Scanner scan=NewScanner (NewBufferedinputstream (system.in)); while(Scan.hasnextint ()) {intn =Scan.nextint (); intm =Scan.nextint (); if(n==0&&m==0){ Break; } intRight3ofn = n%1000; intresult =right3ofn; while(--m!=0) {result= result*right3ofn%1000; } System.out.println (Result); } scan.close (); }}
But, I found a problem.
If I save the 1-999 m-second possible results in a static container, the result is wrong Answer
No idea, who knows?
Here is the Java implementation:
ImportJava.io.BufferedInputStream;Importjava.util.ArrayList;ImportJava.util.Scanner; Public classMain { Public Static voidMain (string[] args) {Scanner scan=NewScanner (NewBufferedinputstream (system.in)); while(Scan.hasnextint ()) {intn =Scan.nextint (); intm =Scan.nextint (); if(n==0&&m==0){ Break; } intRight3ofn = n%1000; ArrayList<Integer> right3s =Arrays.get (RIGHT3OFN); System.out.println (Right3s.get ((M-1)%right3s.size ())); } scan.close (); } Staticarraylist<arraylist<integer>> arrays =Getrightmost3digitarray (); StaticArraylist<arraylist<integer>>Getrightmost3digitarray () {ArrayList<ArrayList<Integer>> arrays =NewArraylist<>(); for(inti = 0; I! = 1000; i + +) {ArrayList<Integer> integers =NewArraylist<>(); intRight3ofi =i; Integers.add (Right3ofi); intRIGHT3 =Right3ofi; while(true) {RIGHT3= RIGHT3 * right3ofi%1000; if(Integers.contains (RIGHT3)) { Break; }Else{integers.add (RIGHT3); }} arrays.add (integers); } returnarrays; }}
hdoj-acm2035 (JAVA) People see people love a^b