2839 | 설탕배달
https://www.acmicpc.net/problem/2839


작성 코드
N = int(input())
N = int(input())
ex = False
for i in range(N // 3 + 1):
for j in range(N // 5 + 1):
if N == 3 * i + 5 * j:
ex = True
print(i + j)
break
if ex:
break
if not ex:
print(-1)
- for 문 2개 사용
이상 코드
N = int(input())
bag = 0
while N >= 0:
# If dived into 5, div and print bag
if N % 5 == 0:
bag += N // 5
print(bag)
break
# If not dived into 5, sub 3 and add 1 bag
N -= 3
bag += 1
else:
print(-1)
- for 문 1개 사용
반응형
'Algorithm > BOJ' 카테고리의 다른 글
| [BOJ] 1051 | 숫자 정사각형 (0) | 2022.02.16 |
|---|---|
| [BOJ]1018 | 체스판 다시 칠하기 (0) | 2022.02.14 |
| [BOJ] 11659 | 구간 합 구하기 4 (0) | 2022.02.09 |
| [BOJ] 18111 | 마인크래프트 (0) | 2022.02.08 |
| [BOJ] 17298 | 오큰수 (0) | 2022.02.04 |
댓글