본문 바로가기
Beakjoon&프로그래머스/Java

[백준/Java] 24296번 ЛИНИЯ

by 현장 2024. 2. 23.

-Code

import java.util.Scanner;

public class _24296 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int res = 2;
        boolean flag = false;

        while (true) {
            int temp = res;

            while (true) {
                if (temp == n) {
                    flag = true;
                    break;
                }

                if (temp > n) {
                    break;
                }

                temp += temp - 1;
            }

            if (flag) {
                break;
            }

            res++;
        }

        System.out.println(res);
    }
}