본문 바로가기
알고리즘/백준

백준 2292 벌집 자바

by reumiii 2019. 10. 30.
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(); // 숫자 N
		// 1 7 19 37 61
		// 6 12 18 24 -> 각각의 간격은 6의 배수로 차이남
		int result = 0; // 지나야하는 방의 개수
		int num = 1;

		while (true) {
			num = num + 6 * result;
			result++;
			if (n <= (num)) {
				break;
			}
		}

		System.out.println(result);
    }
}

댓글