처음에는 배열에 저장하려 했지만 크기가 너무 커진다.
규칙을 찾아본다.
import java.util.Scanner;
public class bj1783 {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
int N = sc.nextInt();
int M = sc.nextInt();
System.out.println(findAnswer(N, M));
sc.close();
}
public static int findAnswer(int N, int M) {
if (N == 1) {
return 1;
}
if (N == 2){
return Math.min(4, (M + 1) / 2);
}
if (M < 7) {
return Math.min(4, M);
}
return M - 2;
}
}