首页 > 代码库 > 题目1441:人见人爱 A ^ B(二分求幂)

题目1441:人见人爱 A ^ B(二分求幂)

题目链接:http://ac.jobdu.com/problem.php?pid=1441

 

详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus

 

参考代码:

////  1441 人见人爱 A ^ B.cpp//  Jobdu////  Created by PengFei_Zheng on 15/04/2017.//  Copyright © 2017 PengFei_Zheng. All rights reserved.// #include <stdio.h>#include <iostream>#include <algorithm>#include <string.h>#include <cmath> using namespace std; int a,b;  int main(){    while(scanf("%d%d",&a,&b)!=EOF){        if(0==a && 0==b) break;        int ans = 1;        while(b!=0){            if(b%2==1){                ans *= a;                ans%=1000;            }            b/=2;            a*=a;            a%=1000;        }        printf("%d\n",ans);    }    return 0;}/**************************************************************    Problem: 1441    User: zpfbuaa    Language: C++    Result: Accepted    Time:0 ms    Memory:1520 kb****************************************************************/

 

题目1441:人见人爱 A ^ B(二分求幂)