A Simple Math Problem | |||
| |||
description | |||
Lele now is thinking about a simple function f(x). If x < 10 f(x) = x. If x >= 10 f(x) = a0 * f(x-1) + a1 * f(x-2) + a2 * f(x-3) + …… + a9 * f(x-10); And ai(0<=i<=9) can only be 0 or 1 . Now, I will give a0 ~ a9 and two positive integers k and m ,and could you help Lele to caculate f(k)%m. | |||
input | |||
The problem contains mutiple test cases.Please process to the end of file. In each case, there will be two lines. In the first line , there are two positive integers k and m. ( k<2*10^9 , m < 10^5 ) In the second line , there are ten integers represent a0 ~ a9. | |||
output | |||
For each case, output f(k) % m in one line. | |||
sample_input | |||
10 9999 1 1 1 1 1 1 1 1 1 1 20 500 1 0 1 0 1 0 1 0 1 0 | |||
sample_output | |||
45 104 | |||
hint | |||
| |||
source题意: 已知函数f(x)满足条件: (1) 当x<10时,f(x)=x; (2) 当x>=10时,f(x)=a0*f(x-1)+a1*f(x-2)+......+an*f(x-10). 其中a0--an是输入的数字,且只能为0或1,给定n和m,求f(n)%m的值。 思路: 可以构造矩阵为 f[n] a0 a1 a2 ... a9 f[n-1]
|
nefu A Simple Math Problem 459 (矩阵连乘)
最新推荐文章于 2024-08-29 22:59:49 发布