CF1789E.Serval and Music Game

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

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 \lt s_2 \lt \ldots \lt s_n. f(x)f(x) is defined as the number of ii (1≤i≤n1\leq i\leq n) that exist non-negative integers pi,qip_i, q_i such that:

s_i=p_ileftlfloors_noverxrightrfloor+q_ileftlceils_noverxrightrceils\_i=p\_i\\left\\lfloor{s\_n\\over x}\\right\\rfloor + q\_i\\left\\lceil{s\_n\\over x}\\right\\rceil

Find out ∑x=1snx⋅f(x)\sum_{x=1}^{s_n} x\cdot f(x) modulo 998 244 353998\,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.

小猫塞尔瓦喜欢玩音乐游戏。他在玩音乐游戏时遇到了一个问题,现在交由你来解决。

给定 nn 个正整数 s1<s2<…<sns_1 \lt s_2 \lt \ldots \lt s_n。定义函数 f(x)f(x) 为满足如下条件的下标 ii(其中 1≤i≤n1\leq i\leq n)的个数:存在非负整数 pi,qip_i, q_i,使得

s_i=p_ileftlfloors_noverxrightrfloor+q_ileftlceils_noverxrightrceils\_i=p\_i\\left\\lfloor{s\_n\\over x}\\right\\rfloor + q\_i\\left\\lceil{s\_n\\over x}\\right\\rceil

请计算 ∑x=1snx⋅f(x)\sum_{x=1}^{s_n} x\cdot f(x) 对 998 244 353998\,244\,353 取模的结果。

提示:⌊x⌋\lfloor x\rfloor 表示不超过 xx 的最大整数(即向下取整),⌈x⌉\lceil x\rceil 表示不小于 xx 的最小整数(即向上取整)。

输入格式

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

The first line of each test cases contains a single integer nn (1≤n≤1061\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 (1≤s1<s2<…<sn≤1071\leq s_1 \lt s_2 \lt \ldots \lt 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.

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

每个测试用例的第一行包含一个整数 nn(1≤n≤1061\leq n\leq 10^6)。

每个测试用例的第二行包含 nn 个正整数 s1,s2,…,sns_1,s_2,\ldots,s_n(1≤s1<s2<…<sn≤1071\leq s_1 \lt s_2 \lt \ldots \lt s_n \leq 10^7)。

保证所有测试用例的 nn 之和不超过 10610^6,且所有测试用例的 sns_n 之和不超过 10710^7。

输出格式

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

对于每个测试用例,在一行中输出一个整数——对所有可能的 xx,求 x⋅f(x)x\cdot f(x) 的和,并对 998 244 353998\,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=p3⋅⌊sn1⌋+q3⋅⌈sn1⌉=1⋅4+0⋅4=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=p2⋅⌊sn2⌋+q2⋅⌈sn2⌉=1⋅2+0⋅2=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=p3⋅⌊sn2⌋+q3⋅⌈sn2⌉=0⋅2+2⋅2=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=p1⋅⌊sn3⌋+q1⋅⌈sn3⌉=1⋅1+0⋅2=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=p2⋅⌊sn3⌋+q2⋅⌈sn3⌉=0⋅1+1⋅2=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=p3⋅⌊sn3⌋+q3⋅⌈sn3⌉=0⋅1+2⋅2=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=p1⋅⌊sn4⌋+q1⋅⌈sn4⌉=1⋅1+0⋅1=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=p2⋅⌊sn4⌋+q2⋅⌈sn4⌉=1⋅1+1⋅1=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=p3⋅⌊sn4⌋+q3⋅⌈sn4⌉=2⋅1+2⋅1=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=14x⋅f(x)=1⋅1+2⋅2+3⋅3+4⋅3=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=1cdotleftlfloor9over3rightrfloor+2cdotleftlceil9over3rightrceil9 = 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 = 1 \\cdot\\left\\lfloor{9\\over 5}\\right\\rfloor + 0 \\cdot\\left\\lceil{9\\over 5}\\right\\rceil$$ $$2 = 0 \\cdot\\left\\lfloor{9\\over 5}\\right\\rfloor + 1 \\cdot\\left\\lceil{9\\over 5}\\right\\rceil$$ $$7 = 3 \\cdot\\left\\lfloor{9\\over 5}\\right\\rfloor + 2 \\cdot\\left\\lceil{9\\over 5}\\right\\rceil$$ $$9 = 3 \\cdot\\left\\lfloor{9\\over 5}\\right\\rfloor + 3 \\cdot\\left\\lceil{9\\over 5}\\right\\rceil

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

对于第一个测试用例,sn=4s_n=4,函数 f(x)f(x) 的计算过程如下:

  • 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。
    • 可以证明,不存在满足条件的 p1,p2p_1,p_2 和 q1,q2q_1,q_2。
    • 令 p3=1p_3=1、q3=0q_3=0,则 s3=p3⋅⌊sn1⌋+q3⋅⌈sn1⌉=1⋅4+0⋅4=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。
    • 可以证明,不存在满足条件的 p1p_1 和 q1q_1。
    • 令 p2=1p_2=1、q2=0q_2=0,则 s2=p2⋅⌊sn2⌋+q2⋅⌈sn2⌉=1⋅2+0⋅2=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。
    • 令 p3=0p_3=0、q3=2q_3=2,则 s3=p3⋅⌊sn2⌋+q3⋅⌈sn2⌉=0⋅2+2⋅2=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。
    • 令 p1=1p_1=1、q1=0q_1=0,则 s1=p1⋅⌊sn3⌋+q1⋅⌈sn3⌉=1⋅1+0⋅2=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。
    • 令 p2=0p_2=0、q2=1q_2=1,则 s2=p2⋅⌊sn3⌋+q2⋅⌈sn3⌉=0⋅1+1⋅2=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。
    • 令 p3=0p_3=0、q3=2q_3=2,则 s3=p3⋅⌊sn3⌋+q3⋅⌈sn3⌉=0⋅1+2⋅2=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。
    • 令 p1=1p_1=1、q1=0q_1=0,则 s1=p1⋅⌊sn4⌋+q1⋅⌈sn4⌉=1⋅1+0⋅1=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。
    • 令 p2=1p_2=1、q2=1q_2=1,则 s2=p2⋅⌊sn4⌋+q2⋅⌈sn4⌉=1⋅1+1⋅1=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。
    • 令 p3=2p_3=2、q3=2q_3=2,则 s3=p3⋅⌊sn4⌋+q3⋅⌈sn4⌉=2⋅1+2⋅1=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。

因此,答案为 ∑x=14x⋅f(x)=1⋅1+2⋅2+3⋅3+4⋅3=26\sum_{x=1}^4 x\cdot f(x) = 1\cdot 1 + 2\cdot 2 + 3\cdot 3 + 4\cdot 3 = 26。

对于第二个测试用例:

  • 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

例如,当 x=3x=3 时,有 f(3)=1f(3)=1,因为存在 p4p_4 和 q4q_4 满足:

9=1⋅⌊93⌋+2⋅⌈93⌉9 = 1 \cdot\left\lfloor{9\over 3}\right\rfloor + 2 \cdot\left\lceil{9\over 3}\right\rceil

可以证明,不存在满足条件的 p1,p2,p3p_1,p_2,p_3 和 q1,q2,q3q_1,q_2,q_3。

当 x=5x=5 时,有 f(5)=4f(5)=4,因为存在如下 pip_i 和 qiq_i:

1 = 1 \cdot\left\lfloor{9\over 5}\right\rfloor + 0 \cdot\left\lceil{9\over 5}\right\rceil$$ $$2 = 0 \cdot\left\lfloor{9\over 5}\right\rfloor + 1 \cdot\left\lceil{9\over 5}\right\rceil$$ $$7 = 3 \cdot\left\lfloor{9\over 5}\right\rfloor + 2 \cdot\left\lceil{9\over 5}\right\rceil$$ $$9 = 3 \cdot\left\lfloor{9\over 5}\right\rfloor + 3 \cdot\left\lceil{9\over 5}\right\rceil

因此,答案为 ∑x=19x⋅f(x)=158\sum_{x=1}^9 x\cdot f(x) = 158。

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

首页