매일 Algorithm

신재원·2023년 5월 31일
1

Algorithm

목록 보기
134/243

백준 1057번 (Silver 4)

import java.util.Scanner;

public class problem446 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int num = in.nextInt();

        int kim = in.nextInt();
        int lim = in.nextInt();

        int count = 1;

        while (true) {

            // 1로 수렴하게 작성
            kim = (kim + 1) / 2;
            lim = (lim + 1) / 2;

            // 탈출 조건
            if (kim == lim) {
                break;
            }
            count++;
        }
        System.out.println(count);
    }
}

0개의 댓글