#P3873. [TJOI2010] 天气预报

    ID: 2810 远端评测题 1500ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>递推2010各省省选线性递推,递推式构造天津

[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 00 and less than or equal to 41464146. To predict the weather of some future day, it uses the weather of the previous nn days. If we denote the weather of day ii by wiw_i (i>ni>n), then $w_i=(a_1\times w_{i-1}+a_2\times w_{i-2}+\cdots+a_{n}\times w_{i-n})\mod4147$, where a1,a2,,ana_1,a_2,\cdots ,a_n are known constants. Given the weather of the first nn days, find the prediction for day mm.

Input Format

The first line of input contains two positive integers nn and mm. The second line contains nn non-negative integers, namely wn,wn1,,w1w_n,w_{n-1},\cdots,w_1. The third line contains nn non-negative integers, namely a1,a2,,ana_1,a_2,\ldots,a_n.

Output Format

Output a single integer, which is the predicted weather for day mm.

2 3
4 5
6 7

59

Hint

1n1001\le n\le 100, n<m107n<m\le10^7, 0ai,wi41460\le a_i,w_i\le 4146.

Time limit per test point: 1.5 seconds.

Translated by ChatGPT 5