acwing 89. a^b

时间:2021-03-15 11:00:17   收藏:0   阅读:0

题目

求 aa 的 bb 次方对 pp 取模的值。

输入格式

三个整数 a,b,pa,b,p ,在同一行用空格隔开。

输出格式

输出一个整数,表示a^b mod p的值。

数据范围

0≤a,b≤1090≤a,b≤109
1≤p≤1091≤p≤109

 

输入样例:

3 2 7 

 

输出样例:

2

 

#include<iostream>
using namespace std;
typedef long long  LL;
int main()
{
    int a,b,p;
    scanf("%d%d%d",&a,&b,&p);
    int res=1%p;
    while(b)
    {
        if(b&1)
        res=(LL)res*a%p;
        a=(LL)a*a%p;
        b>>=1;
    }
    cout<<res<<endl;
    
    return 0;
}

  

  

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!