CF1789E.Serval and Music Game

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Serval loves playing music games. He meets a problem when playing music games, and he leaves it for you to solve.

You are given nn positive integers s1<s2<<sns_1 < s_2 < \ldots < s_n . f(x)f(x) is defined as the number of ii ( 1in1\leq i\leq n ) that exist non-negative integers pi,qip_i, q_i such that:

si=pisnx+qisnxs_i=p_i\left\lfloor{s_n\over x}\right\rfloor + q_i\left\lceil{s_n\over x}\right\rceil

Find out x=1snxf(x)\sum_{x=1}^{s_n} x\cdot f(x) modulo 998244353998\,244\,353 .

As a reminder, x\lfloor x\rfloor denotes the maximal integer that is no greater than xx , and x\lceil x\rceil denotes the minimal integer that is no less than xx.

输入格式

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

The first line of each test cases contains a single integer nn ( 1n1061\leq n\leq 10^6 ).

The second line of each test case contains nn positive integers s1,s2,,sns_1,s_2,\ldots,s_n ( 1s1<s2<<sn1071\leq s_1 < s_2 < \ldots < s_n \leq 10^7 ).

It is guaranteed that the sum of nn over all test cases does not exceed 10610^6 , and the sum of sns_n does not exceed 10710^7 .

输出格式

For each test case, print a single integer in a single line — the sum of xf(x)x\cdot f(x) over all possible xx modulo 998244353998\,244\,353 .

输入输出样例

  • 输入#1

    4
    3
    1 2 4
    4
    1 2 7 9
    4
    344208 591000 4779956 5403429
    5
    1633 1661 1741 2134 2221

    输出#1

    26
    158
    758737625
    12334970

说明/提示

For the first test case, sn=4s_n=4 , f(x)f(x) are calculated as followings:

  • f(1)=1f(1)=1
    • sn1=4\left\lfloor s_n\over 1\right\rfloor=4 , sn1=4\left\lceil s_n\over 1\right\rceil=4 .
    • It can be shown that such p1,p2p_1,p_2 and q1,q2q_1,q_2 that satisfy the conditions don't exist.
    • Let p3=1p_3=1 and q3=0q_3=0 , then s3=p3sn1+q3sn1=14+04=4s_3 = p_3\cdot\left\lfloor s_n\over 1\right\rfloor + q_3\cdot\left\lceil s_n\over 1\right\rceil = 1\cdot 4 + 0\cdot 4 = 4 .
  • f(2)=2f(2)=2
    • sn2=2\left\lfloor s_n\over 2\right\rfloor=2 , sn2=2\left\lceil s_n\over 2\right\rceil=2 .
    • It can be shown that such p1p_1 and q1q_1 that satisfy the conditions don't exist.
    • Let p2=1p_2=1 and q2=0q_2=0 , then s2=p2sn2+q2sn2=12+02=2s_2 = p_2\cdot\left\lfloor s_n\over 2\right\rfloor + q_2\cdot\left\lceil s_n\over 2\right\rceil = 1\cdot 2 + 0\cdot 2 = 2 .
    • Let p3=0p_3=0 and q3=2q_3=2 , then s3=p3sn2+q3sn2=02+22=4s_3 = p_3\cdot\left\lfloor s_n\over 2\right\rfloor + q_3\cdot\left\lceil s_n\over 2\right\rceil = 0\cdot 2 + 2\cdot 2 = 4 .
  • f(3)=3f(3)=3
    • sn3=1\left\lfloor s_n\over 3\right\rfloor=1 , sn3=2\left\lceil s_n\over 3\right\rceil=2 .
    • Let p1=1p_1=1 and q1=0q_1=0 , then s1=p1sn3+q1sn3=11+02=1s_1 = p_1\cdot\left\lfloor s_n\over 3\right\rfloor + q_1\cdot\left\lceil s_n\over 3\right\rceil = 1\cdot 1 + 0\cdot 2 = 1 .
    • Let p2=0p_2=0 and q2=1q_2=1 , then s2=p2sn3+q2sn3=01+12=2s_2 = p_2\cdot\left\lfloor s_n\over 3\right\rfloor + q_2\cdot\left\lceil s_n\over 3\right\rceil = 0\cdot 1 + 1\cdot 2 = 2 .
    • Let p3=0p_3=0 and q3=2q_3=2 , then s3=p3sn3+q3sn3=01+22=4s_3 = p_3\cdot\left\lfloor s_n\over 3\right\rfloor + q_3\cdot\left\lceil s_n\over 3\right\rceil = 0\cdot 1 + 2\cdot 2 = 4 .
  • f(4)=3f(4)=3
    • sn4=1\left\lfloor s_n\over 4\right\rfloor=1 , sn4=1\left\lceil s_n\over 4\right\rceil=1 .
    • Let p1=1p_1=1 and q1=0q_1=0 , then s1=p1sn4+q1sn4=11+01=1s_1 = p_1\cdot\left\lfloor s_n\over 4\right\rfloor + q_1\cdot\left\lceil s_n\over 4\right\rceil = 1\cdot 1 + 0\cdot 1 = 1 .
    • Let p2=1p_2=1 and q2=1q_2=1 , then s2=p2sn4+q2sn4=11+11=2s_2 = p_2\cdot\left\lfloor s_n\over 4\right\rfloor + q_2\cdot\left\lceil s_n\over 4\right\rceil = 1\cdot 1 + 1\cdot 1 = 2 .
    • Let p3=2p_3=2 and q3=2q_3=2 , then s3=p3sn4+q3sn4=21+21=4s_3 = p_3\cdot\left\lfloor s_n\over 4\right\rfloor + q_3\cdot\left\lceil s_n\over 4\right\rceil = 2\cdot 1 + 2\cdot 1 = 4 .

Therefore, the answer is x=14xf(x)=11+22+33+43=26\sum_{x=1}^4 x\cdot f(x) = 1\cdot 1 + 2\cdot 2 + 3\cdot 3 + 4\cdot 3 = 26 .

For the second test case:

  • f(1)=f(2)=f(3)=1f(1)=f(2)=f(3)=1
  • f(4)=3f(4)=3
  • f(5)=f(6)=f(7)=f(8)=f(9)=4f(5)=f(6)=f(7)=f(8)=f(9)=4

For example, when x=3x=3 we have f(3)=1f(3)=1 because there exist p4p_4 and q4q_4 :

9=193+2939 = 1 \cdot\left\lfloor{9\over 3}\right\rfloor + 2 \cdot\left\lceil{9\over 3}\right\rceil

It can be shown that it is impossible to find p1,p2,p3p_1,p_2,p_3 and q1,q2,q3q_1,q_2,q_3 that satisfy the conditions.

When x=5x=5 we have f(5)=4f(5)=4 because there exist pip_i and qiq_i as followings:

1=195+0951 = 1 \cdot\left\lfloor{9\over 5}\right\rfloor + 0 \cdot\left\lceil{9\over 5}\right\rceil

2=095+1952 = 0 \cdot\left\lfloor{9\over 5}\right\rfloor + 1 \cdot\left\lceil{9\over 5}\right\rceil

7=395+2957 = 3 \cdot\left\lfloor{9\over 5}\right\rfloor + 2 \cdot\left\lceil{9\over 5}\right\rceil

9=395+3959 = 3 \cdot\left\lfloor{9\over 5}\right\rfloor + 3 \cdot\left\lceil{9\over 5}\right\rceil

Therefore, the answer is x=19xf(x)=158\sum_{x=1}^9 x\cdot f(x) = 158.

首页