#K43372. Expressing Numbers as Sum of Consecutive Natural Numbers
Expressing Numbers as Sum of Consecutive Natural Numbers
Expressing Numbers as Sum of Consecutive Natural Numbers
You are given a positive integer \( N \). Your task is to determine whether \( N \) can be expressed as the sum of two or more consecutive natural numbers. More formally, check if there exist integers \( a \) and \( k \) (with \( a \ge 1 \) and \( k \ge 1 \)) such that
\( N = a + (a+1) + \cdots + (a+k) \).
If such a representation exists, output YES
; otherwise, output NO
.
inputFormat
The input consists of a single line containing a positive integer \( N \) (\( 1 \le N \le 10^9 \)).
outputFormat
Output a single line: YES
if \( N \) can be expressed as the sum of consecutive natural numbers (with at least two terms), and NO
otherwise.
15
YES