#P3873. [TJOI2010] 天气预报
[TJOI2010] 天气预报
Description
Company A's weather forecasting system works as follows: it represents the weather of a day by an integer greater than or equal to and less than or equal to . To predict the weather of some future day, it uses the weather of the previous days. If we denote the weather of day by (), then $w_i=(a_1\times w_{i-1}+a_2\times w_{i-2}+\cdots+a_{n}\times w_{i-n})\mod4147$, where are known constants. Given the weather of the first days, find the prediction for day .
Input Format
The first line of input contains two positive integers and . The second line contains non-negative integers, namely . The third line contains non-negative integers, namely .
Output Format
Output a single integer, which is the predicted weather for day .
2 3
4 5
6 7
59
Hint
, , .
Time limit per test point: 1.5 seconds.
Translated by ChatGPT 5
京公网安备 11011102002149号