個位數

個位數

已知a和b,求出a^b的個位數。

Input

輸入包含多組測試用例。 每組測試用例,包含兩個數組a和b(0<a,b<=2^30)。

Output

對於每組測試用例,你需要輸出a^b的個位數。

Sample Input

    7 66 8 800

Sample Output

    9 6                    
#include <stdio.h>
int main(void)
{
    int a, b;
    while(scanf("%d%d", &a, &b) == 2)
    {
            int ans[10][5]={
            {0 ,0 ,0 ,0 ,0 },
            {1 ,1 ,1 ,1 ,1 },
            {6 ,2 ,4 ,8 ,6 },
            {1 ,3 ,9 ,7 ,1 },
            {6 ,4 ,6 ,4 ,6 },
            {5 ,5 ,5 ,5 ,5 },
            {6 ,6 ,6 ,6 ,6 },
            {1 ,7 ,9 ,3 ,1 },
            {6 ,8 ,4 ,2 ,6 },
            {1 ,9 ,1 ,9 ,1 },
            };
            printf("%d\n", ans[a%10][b%4]);
        
    }
}

還有一種方法是:只記錄每次運算的個位數即可。

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