Codeforces Round 1024 (Div. 2)
A
Dinner Time
Codeforces
900
原题
←B →
翻译中…

Given four integers $n$, $m$, $p$, and $q$, determine whether there exists an integer array $a_1, a_2, \ldots, a_n$ (elements may be negative) satisfying the following conditions:

翻译中…
  • The sum of all elements in the array is equal to $m$: $$a_1 + a_2 + \ldots + a_n = m$$
  • The sum of every $p$ consecutive elements is equal to $q$: $$a_i + a_{i + 1} + \ldots + a_{i + p - 1} = q,\qquad\text{ for all }1\le i\le n-p+1$$
翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

The first and only line of each test case contains four integers $n$, $m$, $p$, and $q$ ($1 \le p \le n \le 100$, $1 \le q, m \le 100$) — the length of the array, the sum of elements, the length of a segment, and the sum of a segment, respectively.

翻译中…

Output

翻译中…

For each test case, output "YES" (without quotes) if there exists an array satisfying the above conditions, and "NO" (without quotes) otherwise.

翻译中…

You can output "YES" and "NO" in any case (for example, strings "yES", "yes", and "Yes" will all be recognized as valid responses).

翻译中…

Note

翻译中…

In the first test case, an example of an array satisfying the condition is $[1, 0, 1]$. This is because:

翻译中…
  • $a_1+a_2+a_3 = 1+0+1 = 2 = m$
  • $a_1+a_2=1+0=1=q$
  • $a_2+a_3=0+1=1=q$
翻译中…

In the second test case, the only array satisfying the condition is $[1]$.

翻译中…

In the third test case, an example of an array satisfying the condition is $[-2, 5, -2, 5, -2]$.

翻译中…

In the fourth test case, it can be proven that there is no array satisfying the condition.

翻译中…

样例

Input #1
5
3 2 2 1
1 1 1 1
5 4 2 3
10 7 5 2
4 4 1 3
Output #1
YES
YES
YES
NO
NO
InputCopy OutputCopy
题目信息
题号
2102A
时间限制
1 s
内存限制
256 MB
标签
构造
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。