#P11617. [PumpkinOI Round 1] 递推
[PumpkinOI Round 1] 递推
Background
A simple question: what is a recurrence?
Problem Description
Define a recurrence of a sequence as a sequence that satisfies:
$$\sum_{j = 0} ^ m r_j a_{i - j} = 0, \forall i \ge m$$is called the order of this recurrence. In particular, .
You are given the first terms of an infinite sequence and a recurrence of order for the sequence .
Find the sum of all terms of the sequence . Output the answer modulo .
It can be proven that, for any input under modulo , there exists a corresponding sequence in the real-number sense whose sum is convergent.
Input Format
The first line contains a positive integer .
The second line contains integers, representing the first terms of the sequence , i.e. , under modulo .
The third line contains integers, representing the recurrence under modulo .
Output Format
Output one integer on one line, representing the sum of all terms of the sequence modulo .
It is guaranteed that the answer can be represented under modulo . That is, if the final answer is a fraction (it can be proven that the answer must be a rational number), then is guaranteed.
1
1
1 499122176
2
2
1 1
1 199648870 99824435
14
1
1
1 499122177
665496236
Hint
Sample Explanation #1
.
, i.e. . So the sequence is a geometric sequence , and its sum converges to .
Sample Explanation #2
$199648870\equiv -0.6\pmod {998244353},99824435\equiv -0.3\pmod {998244353}$.
$\forall i\ge n,a_i-0.6\times a_{i-1}-0.3\times a_{i-2}=0$, i.e. . After calculation, its sum converges to .
This problem uses bundled/dependent subtasks.
For all subtasks, , . In particular, .
| Subtask ID | Score | Depends On | |
|---|---|---|---|
| None | |||
Translated by ChatGPT 5