The difference between good code and bad code is that good code can use less time, less memory, and mediocre codes do the same thing. But personally I feel better after coming out of the hardware, to write bad code, and the code for the result of the increasing influence of small, meaning there is good Code (digress). The program title is written in the Pixel first time in AC, ha ha ha no reason not to record it.
Subject description, given two plastic A and B, the last three digits B ^ A determined result and returns a string. Direct will have some problems with Pow function, I have not experimented. Similar LeetCode subject is the character string is multiplied. My Notes code is also written in great detail. Direct optimistic about it.
public class the Main { public static void main (String [] args) { System.out.println (tailOfPower ( 2,3 )); } // Description of the problem: given integers and shaping a b, a ^ b is obtained after three, returned as a string @ problems idea: Suppose a * b = c, then the last three bits of c and only a last three and the last three correlation b, and multiplication calculation can be used to calculate described as follows: // // hypothesis 135 * 246, like the results obtained after three h, i, j, the following operational expression // // 135 // * 246 // ------- // abc // EF // G // ------- // HIJ // // can be drawn j = c = bits 5 * 6 = 30, i.e. 0, and the ten binary, into 3 @ I = B + F + bits carry = 3 * 6 + 4 * 5 + 3 = bit 41, i.e. 1, and to one hundred carry, into 4 // H = a + E + G + ten carry = bits 1 * 6 + 4 * 3 + 2 * 5 + 4 = 32, i.e., 2 // get the final three 210. public static String tailOfPower ( int a, int B) { // the last three a is stored, is received by the array of integers, wherein 0 is the index of one hundred, ten bits index 1, index 2 bits int [] = arrTail new new int [. 3 ]; // integer array a first save hundreds place arrTail [0] = (A / 100) 10% ; // second array of integers stored tens arrTail [. 1] = (A / 10) 10% ; // third digit integer array stored arrTail [2] = a% 10; // first time is multiplied A times A, so that the input is three A int [] = INPUT arrTail; // total cycle times b-1, because the first A * A is calculated so that a total of B times for ( int I = 0; I <. 1-B; I ++ ) { // definition of the output of the three-digit int [] = output new new int [. 3 ]; // definition of ten bits to carry int JWG = 0 ; // computing c (as previously shown in equation) int numG = INPUT [2] * arrTail [2 ]; // if c is greater than 0 calculated carry IF (numG> 10 ) { JWG = numG / 10 ; } //C is stored bit of bits output Output [2] = 10% numG ; // too lazy to write, calculate tens to one hundred and carry int the JWS = 0 ; int nums = INPUT [. 1] * arrTail [ 2] + INPUT [2] * arrTail [. 1] + JWG; IF (nums> 10 ) { the JWS = nums / 10 ; } Output [ . 1] = 10% nums ; // calculate the hundreds digit, the carry is not calculated here int NUMB = INPUT [0] * arrTail [2] INPUT + [. 1] * arrTail [. 1] + INPUT [2] * arrTail [0] + the JWS; Output [ 0] = 10% NUMB ; // Debug code, ignore> _ < //for (int = 0 I1; I1 <output.length; I1 ++) { // of System.out.print (Output [I1]); // } // System.out.println (); // the calculated three save digits, which will be the next three digits as input a and the last three are calculated iNPUT = Output; } // will write a string array, after returning string s = "" + input [ 0] + input [. 1] + INPUT [2 ]; return S; } }
The algorithm eventually get 100%.