Product sums

2.5

2 votes
Implementation, Linear Algebra, Fast Fourier transform, C++, Fourier Transformations, Optimization, Math
Problem

You are given four integers a, d, K, and N. Consider N numbers, b1,b2,... ,bN where bi=a+(i1)×d. Your task is to evaluate the following sum:

  • v10,v20,..,vN0v1+v2+..+vN=k(Ni=1bvii) for each k = 0, 1, 2,... , K

Since the sum can be very large, you are required to print it modulo 998244353.

Note: The sum is over all ordered tuples (v1,v2,... ,vN) satisfying Ni=1vi=k.

Input format

  • The first line contains a single integer T denoting the number of test cases.
  • The first line of each test case contains four space-separated integers a, d, K, and N.

Output format

For each test case (in a separate line), print K + 1 space-separated integers in a new line denoting the sum for each k = 0, 1, 2, .. ,K. Print the output modulo 998244353.

Constraints

1T10001a,d,N<9982443531K5×105Sum of K over all test cases does not exceed 106

Sample Input
2
1 3 3 3
2 1 2 4
Sample Output
1 12 105 820
1 14 125
Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

In the first test case we have, a=1,d=3,K=3,N=3. Therefore, b1=1,b2=4,b3=7. We need to sum over tuples of the form (v1,v2,v3) satisfying Ni=1vi=k.

  • For k=0, we have only 1 tuple (0,0,0), and the sum is 1.
  • For k=1, we have 3 possible tuples : (1,0,0),(0,1,0),(0,0,1). The sum comes out to be b1+b2+b3=1+4+7=12.
  • For k=2, we have 6 possible tuples : (2,0,0),(0,2,0),(0,0,2),(1,1,0),(1,0,1),(0,1,1). The sum comes out to be b21+b22+b23+b1b2+b2b3+b1b3=1+16+49+4+28+7=105.
  • For k=3, we have 10 possible tuples : (3,0,0),(0,3,0),(0,0,3),(1,2,0),(2,1,0),(0,1,2),(0,2,1),(1,0,2),(2,0,1),(1,1,1). The sum comes out to be b31+b32+b33+b1b22+b21b2+b2b23+b22b3+b1b23+b21b3+b1b2b3=820.
  • Note that we output answers in a single line.

In the second test case we have, a=2,d=1,K=2,N=4. Therefore, b1=2,b2=3,b3=4,b4=5. We need to sum over tuples of the form (v1,v2,v3,v4) satisfying Ni=1vi=k.

  • For k=0, we have only 1 tuple (0,0,0), and the sum is 1.
  • For k=1, we have 4 possible tuples : (1,0,0,0),(0,1,0,0),(0,0,1,0),(0,0,0,1). The sum comes out to be b1+b2+b3+b4=2+3+4+5=14.
  • For k=2, we have 8 possible tuples. The sum comes out to be b21+b22+b23+b24+b1b2+b2b3+b1b3+b1b4+b2b4+b3b4=125.
  • Note that we output answers in a single line.
Editor Image

?