Created
September 22, 2022 11:38
-
-
Save nattybear/88bad4f60a60234f30206fdba4c69e99 to your computer and use it in GitHub Desktop.
백준 캡틴 이다솜
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def cycleA(x): | |
n = 2 | |
while True: | |
yield x | |
x = x + n | |
n += 1 | |
def cycleB(x): | |
ys = cycleA(1) | |
next(ys) | |
while True: | |
yield x | |
y = next(ys) | |
x = x + y | |
def solution(n): | |
global z | |
xs = cycleB(1) | |
ys = [] | |
for x in xs: | |
if n == x: | |
z += 1 | |
return | |
if n < x: | |
y = ys.pop() | |
z += 1 | |
return solution(n - y) | |
ys.append(x) | |
z = 0 | |
n = int(input()) | |
solution(n) | |
print(z) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment