P880 [CF1626F] A Random Code Problem
NOI
题目描述

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:

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).

Input

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$.

Output

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$.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 10 3 5 13 88
样例输出
382842030
提示

The array in the first example test is $[10, 35, 22]$. In the second example, it is $[15363, 1418543]$.