快速幂入门
时间限制: 1 s
空间限制: 1000 KB
题目等级 : 白银 Silver
题解
题目描述 Description
输入3个数a,b,c,求a^b mod c=?
输入描述 Input Description
三个数a,b,c
输出描述 Output Description
一个数,即a^b mod c 的答案。
样例输入 Sample Input
5 10 9
样例输出 Sample Output
4
数据范围及提示 Data Size & Hint
0
#include<iostream>
using namespace std;
long long a,b,c;
int ksm()
{ long long tmp=a,ans=1;
while (b>0)
{ if (b&1)
ans=ans*tmp%c;
tmp=tmp*tmp%c;
b>>=1;
}
return ans;
}
int main()
{
cin>>a>>b>>c;
cout<<ksm();
}