取余运算

Problem Description

输入b,p,k的值,求b^p mod k的值。

Input

输入有多组数据,每组数据为一行三个数b,p,k,其中b,p,k*k为长整型数。

Output

对于每组数据输出b^p mod k的值。

Sample Input

 2 10 9

Sample Output

 2^10 mod 9=7

 
   
# include 
# include 
using namespace std;

int main()
{
    //freopen("a.txt","r",stdin);
    __int64 b,p,k;
    while(cin>>b>>p>>k)
    {
        int i;
        __int64 sum=1;
        for(i=0;i#include
using namespace stdin; 
int pow_mod(int a,int x,int p)  
{  
    if(x==0) return 1;
    if(x==1) return a%p;  
    long long tmp=pow_mod(a,x>>1,p);
    tmp=(tmp*tmp)%p;
    if(x&1) tmp=tmp*a%p;
    return (int) tmp;
}

int main()
{
    //freopen("b.txt","r",stdin);
    int b,p,k;
    while(cin>>b>>p>>k)
    {
 
   
        cout< 
   
    }
    return 0;
}
 
   
 
  

你可能感兴趣的:(快速取模)