페이지

1009번: 분산처리

https://www.acmicpc.net/problem/1009


#include<stdio.h>
int t, a, b;
int f(int x, int y) {
    if (!y) return 1;
    int r = f(x, y / 2);
    return r*r*(y % 2 ? x : 1) % 10;
}
int main() {
    scanf("%d", &t);
    while (t--) {
        scanf("%d %d", &a, &b);
        printf("%d\n", (f(a, b) + 9) % 10 + 1);
    }
    return 0;
}

댓글 없음 :

댓글 쓰기