No.3243 Multiplication 8 1
タグ : / 解いたユーザー数 62
作問者 : 👑
Problem Statement
You are given an integer $N$. Find the number, modulo $998244353$, of sequences $A$ of length $N$ whose elements are each one of $1, 2, -1, -2$ and which satisfy the following condition.
- There exists a way to split the sequence $A$ into $1$ or more non-empty intervals such that, in every interval after the split, the product of the elements in the interval is $8$.
- More precisely, there exist a positive integer $L$ and an integer sequence $B$ of length $L$ satisfying $0 = B_1 < B_2 < \dots < B_L = N$ such that the following condition holds.
- $A_{B_i + 1} \times A_{B_i + 2} \times \dots \times A_{B_{i+1}} = 8 \ (1 \leq i \leq L - 1)$
You are given $T$ test cases; answer each of them.
Constraints
- All input values are integers.
- $1 \leq T \leq 888$
- $1 \leq N \leq 8.88 \times 10^{17}$
Input
The input is given from standard input in the following format, where $\mathrm{case}_i$ denotes the $i$-th test case.
$T$
$\mathrm{case}_1$
$\mathrm{case}_2$
$\vdots$
$\mathrm{case}_T$
Each case is given in the following format.
$N$
Output
Output $T$ lines. The $i$-th line should contain the answer to the $i$-th test case.
Sample
Sample 1
Input
8 1 3 4 8 88 888 888888888 888000000000000000
Output
0 4 32 9200 744976062 355614226 995875110 722933621
For test case $1$, no sequence $A$ of length $1$ satisfies the condition, so the answer is $0$.
For test case $2$, the sequences $A$ of length $3$ satisfying the condition are $A = (2, 2, 2), (2, -2, -2), (-2, 2, -2), (-2, -2, 2)$, for a total of $4$ sequences.
For test case $3$, examples of sequences $A$ of length $4$ satisfying the condition include $A = (1, 2, -2, -2)$ and $(-2, -2, -2, -1)$, and there are $32$ such sequences in total.
For test case $4$, an example of a sequence $A$ of length $8$ satisfying the condition is $A = (2, 2, -2, 1, -1, -2, 2, -2)$. This is because, by splitting this sequence into $(2, 2, -2, 1, -1)$ and $(-2, 2, -2)$, the product of the elements of each resulting sequence is $8$.
Note that you should output the number of sequences $A$ satisfying the condition modulo $998244353$.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。