#P14199. [ICPC 2024 Hangzhou R] Make It Divisible

[ICPC 2024 Hangzhou R] Make It Divisible

题目描述

Given a sequence a1,a2,,ana_1, a_2, \cdots, a_n of length nn containing positive integers, we say an interval [l,r][l, r] (1lrn1 \le l \le r \le n) is a divisible interval\textit{divisible interval} if there exists an integer dd such that ldrl \le d \le r and for all lirl \le i \le r, aia_i is divisible by ada_d. We say the whole sequence is a divisible sequence\textit{divisible sequence} if for all 1lrn1 \le l \le r \le n, [l,r][l, r] is a divisible interval.

Given another sequence b1,b2,,bnb_1, b_2, \cdots, b_n of length nn and an integer kk, find all integers xx such that 1xk1 \le x \le k and the sequence b1+x,b2+x,,bn+xb_1 + x, b_2 + x, \cdots, b_n + x is a divisible sequence. As the number of such integers might be large, you just need to output the number and the sum of all such integers.

输入格式

There are multiple test cases. The first line of the input contains an integer TT (1T5001 \le T \le 500) indicating the number of test cases. For each test case:

The first line contains two integers nn and kk (1n5×1041 \le n \le 5 \times 10^4, 1k1091 \le k \le 10^9).

The second line contains nn integers b1,b2,,bnb_1, b_2, \cdots, b_n (1bi1091 \le b_i \le 10^9).

It's guaranteed that the sum of nn of all test cases does not exceed 5×1045 \times 10^4.

输出格式

For each test case output one line containing two integers separated by a space, where the first integer is the number of valid xx, and the second integer is the sum of all valid xx.

3
5 10
7 79 1 7 1
2 1000000000
1 2
1 100
1000000000
3 8
0 0
100 5050

提示

For the first sample test case, x=1x = 1, x=2x = 2 and x=5x = 5 are valid.

For the third sample test case, all 1x1001 \le x \le 100 are valid.