1332:幂的末尾

来源:互联网 发布:pps总显示网络不给力 编辑:程序博客网 时间:2024/04/29 08:33

1332:幂的末尾


Description


幂a的b次方的末三位是多少?


Input


多组输入

两个正整数a,b。1<=a<=100,1<=b<=10000。


Output


从高到低输出幂的末三位数字,中间无分隔符。若幂本身不足三位,在前面补零。


Sample Input


3  4


Sample Output


081


Source


#include<cstdio>#include<iostream>using namespace std;long long a,b,p,ans;int main(){    while(cin>>a>>b)    {    p=1000,ans=1;    while(b){        if(b&1) ans=a*ans%p;        a=a*a%p;        b>>=1;    }    printf("%03lld",ans);    cout<<endl;    }    return 0;}



原创粉丝点击