[Huawei machine trial exercise] 50. Calculate the last three digits of M to the power of Npower, and the power of Huawei

Source: Internet
Author: User

[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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.