#C548. Consecutive Sum Representation

    ID: 49133 Type: Default 1000ms 256MiB

Consecutive Sum Representation

Consecutive Sum Representation

You are given a positive integer \( n \). Your task is to determine whether it can be expressed as the sum of two or more consecutive positive integers. If such a representation exists, you should output "YES" followed by the sequence of consecutive numbers. Otherwise, output "NO".

For example, consider \( n = 15 \). One valid sequence is \( 1 + 2 + 3 + 4 + 5 = 15 \), so the output should be YES 1 2 3 4 5. On the other hand, for \( n = 2 \) there is no valid sequence, so the answer should be NO.

The mathematical formulation: Find integers \( a \geq 1 \) and \( k \geq 2 \) such that \[ a + (a+1) + \cdots + (a+k-1) = n \quad \text{or} \quad n = \sum_{i=0}^{k-1} (a+i). \]

inputFormat

The input is given via standard input and it consists of multiple test cases. The first line contains an integer T denoting the number of test cases. Each of the following T lines contains a single integer n.

Example:

3
3
15
2

outputFormat

For each test case, output a single line. If \( n \) can be represented as the sum of at least two consecutive positive integers, print YES followed by the sequence of integers separated by a space. Otherwise, print NO.

Example output corresponding to the input above:

YES 1 2
YES 1 2 3 4 5
NO
## sample
3
3
15
2
YES 1 2

YES 1 2 3 4 5 NO

</p>