#C3622. Partitioning an Integer into Distinct Positive Integers
Partitioning an Integer into Distinct Positive Integers
Partitioning an Integer into Distinct Positive Integers
You are given two integers n and k. Your task is to determine whether it is possible to partition the integer n into exactly k distinct positive integers. The necessary and sufficient condition for such a partition is that n is at least as large as the sum of the first k positive integers, i.e. $$\frac{k(k+1)}{2}$$. If this condition is satisfied, print YES
; otherwise, print NO
.
For example:
- For
n = 8
andk = 3
, the sum of the first 3 positive integers is6
and since8 \ge 6
the answer isYES
. - For
n = 7
andk = 4
, the sum of the first 4 positive integers is10
and since7 < 10
the answer isNO
.
inputFormat
The first line contains an integer T — the number of test cases.
Each of the following T lines contains two space-separated integers n and k, where n is the integer to be partitioned and k is the number of distinct positive integers required.
It is guaranteed that the input is provided via standard input (stdin).
outputFormat
For each test case, output a single line with the string YES
if the partition is possible, or NO
otherwise. The output should be sent to standard output (stdout).
3
8 3
7 4
10 5
YES
NO
NO
</p>