티스토리 뷰

원리는 간단하다.

시작 숫자가 1일 때, 벌집은 1개의 층을 가진다는 개념부터 시작하면,

 

Number Layer
1 1
~7 2
~19 3
~37 4
~61 5

즉, 앞 층의 마지막 숫자에 Layer x 6 을 더해주면 다음 층의 숫자 범위를 구할 수 있다. 

 

Code:

import java.io.IOException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args)  throws IOException {
		Scanner input = new Scanner(System.in);
		int firstInput = input.nextInt();
		int layer = 1;
		int start = 1;
		while(start<firstInput) {
			start = start + (layer*6);
			layer++;
		}
		System.out.println(layer);
       	
	}
}

Comments