The topics are as follows:
The code is as follows:
Package Huawei;public Final class Demo {/* function: The last three digits of the N-side of the solution M (M,n are greater than 10) input parameters: int m:m > int n = > 10 return value:
m the last three digits of the N-th-square */public the static int getlast3digitsofmn (int M, int N) {int result = 1; for (int i = 0;i < N;++i) { result = (Result * (M%))%; } return result;}}
When M, n is large, the n-th of M cannot be represented with the basic data type ... The analysis can be found that the last three bits of the product are only related to the multiplier and the last three bits of the multiplier, but not to the high level, so each time the product result is 1000 modulo ...
Use the loop to find the N-square of M, each multiplication after the first divided by 1000 to take the remainder, otherwise it will result in data overflow, this topic is to test this knowledge point (data overflow).
On-Machine topic (beginner)-The mantissa of high-order number (Java)