hdu 1097 A hard puzzle (快速冪取模)

#include<stdio.h>

int main()
{
    int a, b;
    while (~scanf("%d%d", &a, &b))
    {
        int ans = 1;
        int temp = a%10; //之前這裏沒有進行取模,就WA了
        while (b)
        {
            if (b & 1)
                ans = ans*temp % 10;
            b /= 2;
            temp = (temp*temp) % 10;
        }
        printf("%d\n", ans);
    }
}




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章