매일 Algorithm

신재원·2023년 2월 1일
0

Algorithm

목록 보기
24/243

백준 1009번 : 분산처리

import java.util.Scanner;

public class problem24 {
    public static void main(String[] args) {
        // EX : 3의 7제곱의 일의 자리수로 판별
        Scanner in = new Scanner(System.in);
        int size = in.nextInt();
        int a, b, c;

        for (int i = 0; i < size; i++) {
            a = in.nextInt();
            b = in.nextInt();
            c = 1;
            for (int j = 0; j < b; j++) {
                // 나머지만 계산
                c = (c * a) % 10;
            }
            // 1의 자리가 0일경우
            if (c == 0) {
                c = 10;
            }
            System.out.println(c);
        }
        in.close();
    }
}

0개의 댓글