#abc279g. G - At Most 2 Colors

G - At Most 2 Colors

Score : 600600 points

问题陈述

有一个 1×N1 \times N 的网格,从左到右编号为 1,2,,N1,2,\dots,N

高桥准备了 CC 种颜色的颜料,并用这 CC 种颜色中的任意一种给每个小方格涂色。
然后,在任意连续的 KK 个小方格中,最多有两种颜色。
形式化地讲,对于满足 1iNK+11 \le i \le N-K+1 的所有整数 ii,在第 i,i+1,,i+K1i,i+1,\dots,i+K-1 个小方格中最多有两种颜色。

高桥有多少种不同的涂色方式?
由于这个数字可能非常大,请计算它对 998244353998244353 取模的结果。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There is a grid with 1×N1 \times N squares, numbered 1,2,,N1,2,\dots,N from left to right.

Takahashi prepared paints of CC colors and painted each square in one of the CC colors.
Then, there were at most two colors in any consecutive KK squares.
Formally, for every integer ii such that 1iNK+11 \le i \le N-K+1, there were at most two colors in squares i,i+1,,i+K1i,i+1,\dots,i+K-1.

In how many ways could Takahashi paint the squares?
Since this number can be enormous, find it modulo 998244353998244353.

Constraints

  • All values in the input are integers.
  • 2KN1062 \le K \le N \le 10^6
  • 1C1091 \le C \le 10^9

Input

The input is given from Standard Input in the following format:

NN KK CC

Output

Print the answer as an integer.

Sample Input 1

3 3 3

Sample Output 1

21

In this input, we have a 1×31 \times 3 grid.
Among the 2727 ways to paint the squares, there are 66 ways to paint all squares in different colors, and the remaining 2121 ways are such that there are at most two colors in any consecutive three squares.

Sample Input 2

10 5 2

Sample Output 2

1024

Since C=2C=2, no matter how the squares are painted, there are at most two colors in any consecutive KK squares.

Sample Input 3

998 244 353

Sample Output 3

952364159

Print the number modulo 998244353998244353.

update @ 2024/3/10 11:45:24