run2ai / algorithm-taek

0 stars 0 forks source link

연속된 자연수의 합 구하기 #7

Closed Blzae97 closed 2 months ago

Blzae97 commented 2 months ago

연속된 자연수의 합 구하기

teang1995 commented 2 months ago
# https://www.acmicpc.net/problem/2018
import sys

N = int(sys.stdin.readline())

start = 1
end = 1
ans = 1
s = 1

while end != N:
    if s < N:
        end += 1
        s += end
        continue

    if s > N:
        s -= start
        start += 1
        continue

    if s == N:
        ans += 1
        end += 1
        s += end
        continue

print(ans)