Skip to content

Commit 7b956b6

Browse files
committed
[Silver III] Title: 삼삼한 수 2, Time: 36 ms, Memory: 32412 KB -BaekjoonHub
1 parent db9c098 commit 7b956b6

2 files changed

Lines changed: 69 additions & 0 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# [Silver III] 삼삼한 수 2 - 17253
2+
3+
[문제 링크](https://www.acmicpc.net/problem/17253)
4+
5+
### 성능 요약
6+
7+
메모리: 32412 KB, 시간: 36 ms
8+
9+
### 분류
10+
11+
수학
12+
13+
### 제출 일자
14+
15+
2025년 6월 26일 15:47:54
16+
17+
### 문제 설명
18+
19+
<p>준하는 3의 거듭제곱인 수만 사용하여 만들 수 있는 수를 보면 삼삼한 느낌을 받는다.</p>
20+
21+
<p>이 느낌을 정확히 설명하자면, 3의 거듭제곱인 수들을 겹치지 않고 한번씩만 더해서 어떤 수 x를 만들 수 있다면 그 수는 삼삼하다고 한다. 삼삼한 수는 3의 거듭제곱인 수가 반드시 하나 이상 포함되어야 한다.</p>
22+
23+
<p>예를 들어, 109는 3<sup>0</sup>+3<sup>3</sup>+3<sup>4</sup>로 나타낼 수 있으므로 삼삼한 수이다. 하지만 7과 18은 삼삼하지 않다.</p>
24+
25+
<p>준하는 삼삼한 수가 얼마나 더 있는 지 알아보려고 한다.</p>
26+
27+
### 입력
28+
29+
<p>첫째 줄에 9,223,372,036,854,775,807보다 작거나 같은 음이 아닌 정수 N이 입력된다.</p>
30+
31+
### 출력
32+
33+
<p>입력된 수가 삼삼하다면 YES, 그렇지 않다면 NO를 출력한다.</p>
34+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# 17253 삼삼한 수 2
2+
# 실버 3
3+
4+
from itertools import combinations
5+
6+
import sys
7+
input = sys.stdin.readline
8+
9+
N = int(input())
10+
used = []
11+
12+
def check3(N): # N이 포함할 수 있는 가장 큰 3의 거듭제곱
13+
idx = 0
14+
while True:
15+
if 3**idx > N:
16+
idx -= 1
17+
break
18+
idx += 1
19+
20+
return idx
21+
22+
while True:
23+
idx = check3(N)
24+
#print('idx : ', idx)
25+
26+
if idx in used:
27+
print("NO")
28+
break
29+
else:
30+
used.append(idx)
31+
32+
N -= 3**idx
33+
if N == 0:
34+
print("YES")
35+
break

0 commit comments

Comments
 (0)