[Huawei machine trial exercise] 50. Calculate the last three digits of M to the power of Npower, and the power of Huawei
Question
Description:
The Npower of a positive integer M may be a very large number. We only need to calculate the last three digits of this number. For example, if the values of input 5 and 3 are 125, the output value is 125 for example 2. For example, if the value of 10 in input 2 and 10 2 is 1024, the output value is 24 for example 3. For example, the value of 5 in input 111 and 5 111 is 116850581551, the output result is 551.
Exercise phase:
Elementary
Code
/* ------------------------------------- * Date: 2015-07-04 * Author: SJF0115 * question: Find the last three digits of the Npower of M * Source: huawei machine trial exercise questions ----------------------------------------- */# include <iostream> # include "oj. h "using namespace std; unsigned int GetLastThreeNumOfResult (unsigned int m, unsigned int n) {unsigned int result = 1; for (int I = 0; I <n; ++ I) {result = (result * (m % 1000) % 1000;} // for return result ;}
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.