codevs3500 快速幂入门题解

codevs3500 快速幂入门题解

//我也是抄的题解

题目描述 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<a,b,c<10000000000000000

#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int mi(long long &a,long long &b,long long &c)
{
    long long ans=1;
    while(b>0)
    {
        if(b&1==1)
          ans=(ans*a)%c;
        a=(a*a)%c;
        b>>=1;
    }
    cout<<ans<<endl;
}
int main()
{
    long long a,b,c;
    cin>>a>>b>>c;
    mi(a,b,c);
    return 0;
}

 

posted @ 2016-05-08 11:27  笑面  阅读(216)  评论(0编辑  收藏  举报