-
BaekJoon[1789]코딩/백준 그리디 문제 2023. 2. 17. 13:11
일단 가장 많이 자연수를 사용하기위해서 n(n+1)/2<=m
을만족하는 n의 최대값을 구해야하는데
n<=sqrt(2*m)이 항상 참임으로 n+=1방식이 아닌 n-=1방식을 채용한다(n+=1은 시간이 더오래걸리기때문)
import math I=int(input()) C=int(math.sqrt(2*I)) while True: if C*(C+1)<=2*I: print(C) break else: C-=1
'코딩 > 백준 그리디 문제' 카테고리의 다른 글
BaekJoon[4796] (0) 2023.02.17 BaekJoon[2437] (0) 2023.02.17 BaekJoon[1449] (0) 2023.02.17 BaekJoon[1339] (0) 2023.02.17 BaekJoon[16953] (0) 2023.02.17