CF1928E.Modular Sequence

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given two integers xx and yy . A sequence aa of length nn is called modular if a1=xa_1=x , and for all 1<in1 < i \le n the value of aia_{i} is either ai1+ya_{i-1} + y or ai1modya_{i-1} \bmod y . Here xmodyx \bmod y denotes the remainder from dividing xx by yy .

Determine if there exists a modular sequence of length nn with the sum of its elements equal to SS , and if it exists, find any such sequence.

输入格式

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

The first and only line of each test case contains four integers nn , xx , yy , and ss ( 1n21051 \le n \le 2 \cdot 10^5 , 0x21050 \le x \le 2 \cdot 10^5 , 1y21051 \le y \le 2 \cdot 10^5 , 0s21050 \le s \le 2 \cdot 10^5 ) — the length of the sequence, the parameters xx and yy , and the required sum of the sequence elements.

The sum of nn over all test cases does not exceed 21052 \cdot 10^5 , and also the sum of ss over all test cases does not exceed 21052 \cdot 10^5 .

输出格式

For each test case, if the desired sequence exists, output "Yes" on the first line (without quotes). Then, on the second line, output nn integers a1,a2,,ana_1, a_2, \ldots, a_n separated by a space — the elements of the sequence aa . If there are multiple suitable sequences, output any of them.

If the sequence does not exist, output "No" on a single line.

You can output each letter in any case (lowercase or uppercase). For example, the strings "yEs", "yes", "Yes", and "YES" will be accepted as a positive answer.

输入输出样例

  • 输入#1

    3
    5 8 3 28
    3 5 3 6
    9 1 5 79

    输出#1

    YES
    8 11 2 2 5 
    NO
    NO

说明/提示

In the first example, the sequence [8,11,2,5,2][8, 11, 2, 5, 2] satisfies the conditions. Thus, a1=8=xa_1 = 8 = x , a2=11=a1+3a_2 = 11 = a_1 + 3 , a3=2=a2mod3a_3 = 2 = a_2 \bmod 3 , a4=5=a3+3a_4 = 5 = a_3 + 3 , a5=2=a4mod3a_5 = 2 = a_4 \bmod 3 .

In the second example, the first element of the sequence should be equal to 55 , so the sequence [2,2,2][2, 2, 2] is not suitable.

首页