백준 2292 자바(벌집)

정호윤·2023년 3월 6일

자바

목록 보기
16/46


import java.util.*;
import java.io.*;
public class Main {

  
   
    public static void main(String[] args) throws IOException{
        Scanner sc = new Scanner(System.in);
        int N  =sc.nextInt();

        int count = 1; 
        int range = 2; // 2번째칸부터 시작한다는 소리.1은 따로 뺐으니까
        if(N==1) System.out.println(1);
        else{
            while(range<=N){
                range = range+(6*count);
                count++;
            }
            System.out.println(count);
        }
    }
}

range는 칸의 개수이다.1은 따로 뺐으니까 2부터 시작한다.

profile
개발자로 취직을 희망합니다.

0개의 댓글