X = int(input())
sticks = [64]
while sum(sticks) > X:
new_smallest_stick = sticks[-1] / 2
sum_sticks = sum(sticks)
sticks[-1] = new_smallest_stick
if sum_sticks - new_smallest_stick < X:
sticks.append(new_smallest_stick)
print(len(sticks))
다른 사람 풀이
숏코딩
print(bin(int(input())).count('1'))
필요한 막대의 개수이기 때문에, 이진법으로 표현해서 1의 개수를 출력해도 된다.
출처
- https://www.acmicpc.net/problem/1094
'코딩테스트' 카테고리의 다른 글
[백준 1181번][python] 단어 정렬 (0) | 2024.09.26 |
---|---|
[백준 2751번][python] 수 정렬하기 2 (3) | 2024.09.26 |
[백준 1010번][python] 다리 놓기 (1) | 2024.09.21 |
[백준 1032번][python] 명령 프롬프트 (1) | 2024.09.21 |
[백준 25206번][python] 너의 평점은 (2) | 2024.09.21 |