杭电 2035 人见人爱A^B【快速幂取模】

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2035

解题思路:这一题数据不大,可以用同余来做,也可以用快速幂来做

反思:定义成

#include<stdio.h>

int  quick_mod(int   a,int b,int m)

{

    int ans=1;

    while(b)

    {

        if(b&1)

        {

            ans=(ans*a)%m;

            b--;

        }

        b=b>>1;

        a=a*a%m;

    }

    return ans;

}

int main()

{

    int a,b;

    int m=1000;

    while(scanf("%d %d",&a,&b)!=EOF&&a&&b)

    {

        printf("%d\n",quick_mod(a,b,m));

    }

}

  

long long 时不能通过,不知道为啥。

 

你可能感兴趣的:(杭电)