import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int T,a,b,tmp,objNum,result;
List<Integer> lastNum = new ArrayList<>();
Scanner sc = new Scanner(System.<i>in</i>);
T = sc.nextInt();
for(int i=0;i<T;i++){
a = sc.nextInt();
b = sc.nextInt();
lastNum.clear();
a %= 10; //계산량 감소시키기 // 어차피 결과는 똑같음
for(int j=1;j<=4;j++){ //입력받은 a^b 의 가능한 1의자리들을 lastNum배열에 입력
// 주기는 최대 4임
tmp = (int)Math.<i>pow</i>(a,j) % 10;
if(lastNum.contains(tmp)) break;
else lastNum.add(tmp);
}
objNum = b%lastNum.size()-1; //배열에서 objNum번째의 숫자가 컴퓨터 번호임
if(objNum < 0) objNum += lastNum.size();
if(lastNum.get(objNum) == 0) result = 10; //10번 컴퓨터 처리
else result = lastNum.get(objNum);
System.<i>out</i>.println(result);
}
sc.close();
}
}
왜 인지는 모르겠는데 이걸로 하니까 정답이네요
ryansewook 1년 전
분명히 제대로 한거같은데 그냥 틀렸답니다....