카테고리 없음

[백준/Python] 2018번: 수들의 합 5

Jinn_12609 2025. 1. 25. 01:26

문제

 

https://www.acmicpc.net/problem/2018

 


Algorithm

 

 


 

 

Code

import sys
input = sys.stdin.readline
N = int(input())
start = 1
end = 1
total = 1
count = 1

if N == 1 or N == 2:
    print(1)
    sys.exit()

while end < N//2 + 2:
  if total == N:
    count += 1
    end += 1
    total = total + end
  elif total < N:
    end += 1
    total = total + end
  else:
    total = total - start
    start += 1
print(count)