CF1789E Serval and Music Game

题目描述

给定整数 $n$ 和长度为 $n$ 的**递增**序列 $s$。 定义 $f(x)$ 为满足下列要求的整数 $i(1\leq i\leq n)$ 的数量: - 存在**非负整数** $p_i,q_i$ 使得 $s_i=p_i\bigg\lfloor\dfrac{s_n}{x}\bigg\rfloor+q_i\bigg\lceil\dfrac{s_n}{x}\bigg\rceil$。 你需要求出 $\sum_{x=1}^{s_n}x\times f(x)$ 对 $998244353$ 取模后的值。 每个测试点包含 $t$ 组数据。

输入格式

第一行输入一个整数 $t(1\leq t\leq10^4)$ 表示数据组数,接下来对于每组数据: 第一行输入一个整数 $n(1\leq n\leq10^6)$。 接下来输入一行 $n$ 个整数表示序列 $s(1\leq s_1

输出格式

对于每组数据: 输出一行一个整数表示 $\sum_{x=1}^{s_n}x\times f(x)$ 对 $998244353$ 取模后的值。

说明/提示

For the first test case, $ s_n=4 $ , $ f(x) $ are calculated as followings: - $ f(1)=1 $ - $ \left\lfloor s_n\over 1\right\rfloor=4 $ , $ \left\lceil s_n\over 1\right\rceil=4 $ . - It can be shown that such $ p_1,p_2 $ and $ q_1,q_2 $ that satisfy the conditions don't exist. - Let $ p_3=1 $ and $ q_3=0 $ , then $ s_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)=2 $ - $ \left\lfloor s_n\over 2\right\rfloor=2 $ , $ \left\lceil s_n\over 2\right\rceil=2 $ . - It can be shown that such $ p_1 $ and $ q_1 $ that satisfy the conditions don't exist. - Let $ p_2=1 $ and $ q_2=0 $ , then $ s_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 $ p_3=0 $ and $ q_3=2 $ , then $ s_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)=3 $ - $ \left\lfloor s_n\over 3\right\rfloor=1 $ , $ \left\lceil s_n\over 3\right\rceil=2 $ . - Let $ p_1=1 $ and $ q_1=0 $ , then $ s_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 $ p_2=0 $ and $ q_2=1 $ , then $ s_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 $ p_3=0 $ and $ q_3=2 $ , then $ s_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)=3 $ - $ \left\lfloor s_n\over 4\right\rfloor=1 $ , $ \left\lceil s_n\over 4\right\rceil=1 $ . - Let $ p_1=1 $ and $ q_1=0 $ , then $ s_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 $ p_2=1 $ and $ q_2=1 $ , then $ s_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 $ p_3=2 $ and $ q_3=2 $ , then $ s_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 $ \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)=1 $ - $ f(4)=3 $ - $ f(5)=f(6)=f(7)=f(8)=f(9)=4 $ For example, when $ x=3 $ we have $ f(3)=1 $ because there exist $ p_4 $ and $ q_4 $ : $$ 9 = 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 $ p_1,p_2,p_3 $ and $ q_1,q_2,q_3 $ that satisfy the conditions. When $ x=5 $ we have $ f(5)=4 $ because there exist $ p_i $ and $ q_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 $ \sum_{x=1}^9 x\cdot f(x) = 158$.