hdu6063-RXD and math

来源:互联网 发布:c语言数据类型举例 编辑:程序博客网 时间:2024/05/18 01:51

    唉,我等弱鸡只能水一水水题了,这第三场这么多数学公式,真是难为我这个公式恐惧症了,这道题就是打表找到规律,发现答案就是(n^k%mod),然后用到快速幂,然后注意一下,快速幂的时候可能会超过long long 导致溢出,那么久要先mod再乘了,时间复杂度:log(n).

#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>#include <queue>#include <vector>#include <math.h>#define LL long longusing namespace std;const int maxn = 1e5+5;const LL mod=1e9+7;LL quck_mod(LL x,LL y){    LL ret=1;    //x=x%mod;    while(y>0){        if(y&1) ret=((ret%mod)*(x%mod))%mod;        x=((x%mod)*(x%mod))%mod;        y>>=1;    }    return ret;}int main(){    LL n,k;    int cas=1;    while(scanf("%lld%lld",&n,&k)!=EOF)    {        LL ans=quck_mod(n,k);        printf("Case #%d: %lld\n",cas++,ans%mod);    }    return 0;}