This problem is the deformation of the Hdoj 1061:
1061: N-order single digit of n http://www.cnblogs.com/xiezie/p/5596779.html
1097: The single digit of the m order of N
Therefore, it is not here to repeat the
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.hasnext ()) {intn =Scan.nextint (); intm =Scan.nextint (); intRightmostdigitofn = n%10; ArrayList<Integer> rightmostdigits =Arrays.get (RIGHTMOSTDIGITOFN); intSize =rightmostdigits.size (); if(Size = = 1) {System.out.println (RIGHTMOSTDIGITOFN); }Else{System.out.println (Rightmostdigits.get ((M-1)%size)); }} scan.close (); } Staticarraylist<arraylist<integer>> arrays =Getrightmostdigitarray (); StaticArraylist<arraylist<integer>>Getrightmostdigitarray () {ArrayList<ArrayList<Integer>> arrays =NewArraylist<>(); for(inti = 0; I! = 10; i + +) {ArrayList<Integer> integers =NewArraylist<>(); Integers.add (i); intn = 2; while(true){ intRightmostdigit = (int) (Math.pow (i, N)%10); if(rightmostdigit==i) { Break; }Else{integers.add (rightmostdigit); } N++; } arrays.add (integers); } returnarrays; }}
hdoj-acm1097 (JAVA) A hard Puzzle