Example 4.10 cute A ^ B
Title Description
A ^ B integer seek the last three digits of the representation. Description: A ^ B is the meaning of "A, B power"
Entry
Input data comprising a plurality of test cases, one row for each instance, two positive integers A and B (), if A = 0, B = 0, it indicates the end of input data, without processing.
Export
For each test case, output a final three A ^ B integer representation, each output per line.
Sample input
2 3 12 6 6789 10000 0 0
Sample Output
8 984 1
Problem-solving Code
#include <cstdio> int main () { int A, B; the while (Scanf ( " % D% D " , A &, & B) =! the EOF) { IF (A == 0 && B == 0 ) BREAK ; int = ANS . 1 ; // save the results of the final variable initial value. 1 the while (! b = 0 ) // if b is 0, i.e., a binary conversion process ends b of { IF (b% 2 == . 1 ) // current bit is 1, it is necessary that multiplies a 2 ^ k times to the variables ANS * = { ANS a; ANS % = 1000 ; // find the last three digits } B / = 2 ; // B is divided by 2 a * = a; // find the next bit weight, i.e. starting from a time of 1 , find a sequence of 2 times, 4 times ...... a% = 1000 ; // find after a three } // while a binary value of b is calculated, while calculating a 2 ^ k times, and part to the desired multiplicative ANS the printf ( " % D \ n- " , ANS); } return 0 ; }