[Huawei Machine Test exercises]50. The last three digits of the n-th side of M

Source: Internet
Author: User

Topic

Describe:

正整数M 的N次方有可能是一个非常大的数字,我们只求该数字的最后三位例1:比如输入5和3 ,5的3次方为125,则输出为125 例2:比如输入2和10  2的10次方为1024 ,则输出结果为24例3:比如输入111和5  111的5次方为116850581551,则输出结果为551

Practice Stage:

Code

/* ---------------------------------------* Date: 2015-07-04* sjf0115* title: The last three bits of the n-th side of M * Source: Huawei Machine Test Exercises----------------- ------------------------*/#include <iostream>#include "oj.h"using namespace STD;unsigned intGetlastthreenumofresult (unsigned intMunsigned intN) {unsigned intresult =1; for(inti =0; i < n;++i) {result = (Result * (M%) +)) % +; }//for    returnResult;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

[Huawei Machine Test exercises]50. The last three digits of the n-th side of M

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.