A14814 | A Random Code Problem
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given an integer array $a_0, a_1, \dots, a_{n - 1}$ , and an integer $k$ . You perform the following code with it:
```
<pre class="lstlisting">```
long long ans = 0; // create a 64-bit signed variable which is initially equal to 0<br></br>for(int i = 1; i <= k; i++)<br></br>{<br></br> int idx = rnd.next(0, n - 1); // generate a random integer between 0 and n - 1, both inclusive<br></br> // each integer from 0 to n - 1 has the same probability of being chosen<br></br> ans += a[idx];<br></br> a[idx] -= (a[idx] % i);<br></br>}<br></br>
```
```
Your task is to calculate the expected value of the variable ans after performing this code.
Note that the input is generated according to special rules (see the input format section).
```
<pre class="lstlisting">```
long long ans = 0; // create a 64-bit signed variable which is initially equal to 0<br></br>for(int i = 1; i <= k; i++)<br></br>{<br></br> int idx = rnd.next(0, n - 1); // generate a random integer between 0 and n - 1, both inclusive<br></br> // each integer from 0 to n - 1 has the same probability of being chosen<br></br> ans += a[idx];<br></br> a[idx] -= (a[idx] % i);<br></br>}<br></br>
```
```
Your task is to calculate the expected value of the variable ans after performing this code.
Note that the input is generated according to special rules (see the input format section).
输入格式
The only line contains six integers $n$ , $a_0$ , $x$ , $y$ , $k$ and $M$ ( $1 \le n \le 10^7$ ; $1 \le a_0, x, y < M \le 998244353$ ; $1 \le k \le 17$ ).
The array $a$ in the input is constructed as follows:
- $a_0$ is given in the input;
- for every $i$ from $1$ to $n - 1$ , the value of $a_i$ can be calculated as $a_i = (a_{i - 1} \cdot x + y) \bmod M$ .
The array $a$ in the input is constructed as follows:
- $a_0$ is given in the input;
- for every $i$ from $1$ to $n - 1$ , the value of $a_i$ can be calculated as $a_i = (a_{i - 1} \cdot x + y) \bmod M$ .
输出格式
Let the expected value of the variable ans after performing the code be $E$ . It can be shown that $E \cdot n^k$ is an integer. You have to output this integer modulo $998244353$ .
输入输出样例
输入 #1
3 10 3 5 13 88
输出 #1
382842030
输入 #2
2 15363 270880 34698 17 2357023
输出 #2
319392398
The array in the first example test is $[10, 35, 22]$ . In the second example, it is $[15363, 1418543]$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted