数学_二分幂取模(HDU_1097)

b 值大,取二分幂计算

#include <stdio.h>
#include <string.h>

#define M

int main(int argc, char* argv[])
{
    #ifdef __MYLOCAL
    freopen("in.txt","r",stdin);
    #endif

    int a,b,c,t;
    while(scanf("%d%d",&a,&b) != EOF)
    {
        c = 1, t = a % 10;
        while(b > 0)
        {
            b % 2 == 1 ? c = c * t % 10 : NULL;
            b >>= 1;
            t = t * t % 10;
        }
        printf("%d\n",c);
    }

    return 0;
}

 

posted on 2013-08-07 20:18  lk1993  阅读(171)  评论(0编辑  收藏  举报