백준
백준 2018: 수들의 합 5
2호0
2023. 1. 27. 20:38
https://www.acmicpc.net/problem/2018
2018번: 수들의 합 5
어떠한 자연수 N은, 몇 개의 연속된 자연수의 합으로 나타낼 수 있다. 당신은 어떤 자연수 N(1 ≤ N ≤ 10,000,000)에 대해서, 이 N을 몇 개의 연속된 자연수의 합으로 나타내는 가지수를 알고 싶어한
www.acmicpc.net
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
n = int(input())
sum = 1
count = 1
start_index = 1
end_index = 1
while end_index!=n:
if sum < n:
end_index+=1
sum +=end_index
elif sum == n:
count+=1
end_index+=1
sum+=end_index
else:
sum-=start_index
start_index+=1
print(count)
|
cs |