CF1928E.Modular Sequence

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

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<i≤n1 \lt i \le n the value of aia_{i} is either ai−1+ya_{i-1} + y or ai−1 mod ya_{i-1} \bmod y. Here x mod yx \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.

给你两个整数 xx 和 yy。一个长度为 nn 的序列 aa 被称为模序列(modular sequence),如果满足:a1=xa_1 = x,且对所有 1<i≤n1 < i \le n,aia_i 的值为 ai−1+ya_{i-1} + y 或 ai−1 mod ya_{i-1} \bmod y。其中 x mod yx \bmod y 表示 xx 除以 yy 所得的余数。

判断是否存在一个长度为 nn 的模序列,使得其所有元素之和恰好等于 SS;若存在,输出任意一个满足条件的序列。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤2⋅1041 \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 (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5, 0≤x≤2⋅1050 \le x \le 2 \cdot 10^5, 1≤y≤2⋅1051 \le y \le 2 \cdot 10^5, 0≤s≤2⋅1050 \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 2⋅1052 \cdot 10^5, and also the sum of ss over all test cases does not exceed 2⋅1052 \cdot 10^5.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤2⋅1041 \le t \le 2 \cdot 10^4)。随后是各测试用例的描述。

每个测试用例仅有一行,包含四个整数 nn、xx、yy 和 ss(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5,0≤x≤2⋅1050 \le x \le 2 \cdot 10^5,1≤y≤2⋅1051 \le y \le 2 \cdot 10^5,0≤s≤2⋅1050 \le s \le 2 \cdot 10^5)——分别表示序列长度、参数 xx 和 yy,以及序列元素之和的要求值。

所有测试用例的 nn 之和不超过 2⋅1052 \cdot 10^5,且所有测试用例的 ss 之和也不超过 2⋅1052 \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.

对于每个测试用例,如果所要求的序列存在,则在第一行输出“Yes”(不带引号)。然后,在第二行输出 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n,以空格分隔——即序列 aa 的各元素。若存在多个满足条件的序列,输出任意一个即可。

如果该序列不存在,则在单独一行输出“No”。

你可以以任意大小写形式输出每个字母(小写或大写)。例如,字符串 "yEs"、"yes"、"Yes" 和 "YES" 均被视为有效的肯定回答。

输入输出样例

  • 输入#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=a2 mod 3a_3 = 2 = a_2 \bmod 3, a4=5=a3+3a_4 = 5 = a_3 + 3, a5=2=a4 mod 3a_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.

在第一个例子中,序列 [8,11,2,5,2][8, 11, 2, 5, 2] 满足条件。因此,a1=8=xa_1 = 8 = x,a2=11=a1+3a_2 = 11 = a_1 + 3,a3=2=a2 mod 3a_3 = 2 = a_2 \bmod 3,a4=5=a3+3a_4 = 5 = a_3 + 3,a5=2=a4 mod 3a_5 = 2 = a_4 \bmod 3。

在第二个例子中,序列的第一个元素应等于 55,因此序列 [2,2,2][2, 2, 2] 不满足要求。

输入解题思路,AI测评打分。不知道怎么写?

首页