Skip to content

Instantly share code, notes, and snippets.

@nattybear
Created September 22, 2022 11:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nattybear/88bad4f60a60234f30206fdba4c69e99 to your computer and use it in GitHub Desktop.
Save nattybear/88bad4f60a60234f30206fdba4c69e99 to your computer and use it in GitHub Desktop.
백준 캡틴 이다솜
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