YWC

백준/2292/벌집/C/Python 본문

공부/코테_문제풀이

백준/2292/벌집/C/Python

YWC 2023. 9. 11. 09:36

https://www.acmicpc.net/problem/2292

 

1620번: 나는야 포켓몬 마스터 이다솜

첫째 줄에는 도감에 수록되어 있는 포켓몬의 개수 N이랑 내가 맞춰야 하는 문제의 개수 M이 주어져. N과 M은 1보다 크거나 같고, 100,000보다 작거나 같은 자연수인데, 자연수가 뭔지는 알지? 모르면

www.acmicpc.net

 


1) c

#include <stdio.h>
#include <stdlib.h>
#pragma warning(disable:4996)

int main(void) {
    int n,start,end; n=start=end = 1;
    scanf("%d", &n);
    if (n == 1) { printf("1"); return 0; }
    for (int i = 2;; i++) {
        if ((start <= n) && (n <= end)) { printf("%d", i-1); return 0; }
        start = end + 1;
        end = (start - 1) + 6 * (i - 1);
        //printf("%d)%d %d\n",i, start, end);
    }
    
    return 0;
}

 


2) Python

if __name__== "__main__":
    n = int(input())
    start, end = 1,1

    if n==1:
        print(1)
    else:
        i =2
        while(True):
            if (start<=n) and (n<=end):
                print(i-1)
                break
            start = end+1
            end = (start-1) + 6*(i-1)
            #print(i,"::", start, ",",end)
            i = i+1

 

'공부 > 코테_문제풀이' 카테고리의 다른 글

백준/1259/팰린드롬수/C/Python  (0) 2023.09.11
백준/2798/블랙잭/C/Python  (0) 2023.09.11
백준/2231/분해합/C/Python  (0) 2023.09.06
백준/1978/소수찾기/Python  (0) 2023.09.05
백준/4153/직각삼각형/C/python  (0) 2023.09.04