GS is suffering from tons of boring math assignment. He find it make him tired and impatient so he asks you to finish his assignment in hope that he could hang out in many places of interest and enjoy his life.
In this assignment, you’re asked to solve the following problem:
Given a recurrent function
and boundary values
You should solve for f[n].
What a easy problems! Wait for a moment, you see a few lines in the last paragraph. It reads as follows: To make the problem a little hard, you are now informed that, at some special values of n (there are q such values, namely n
1, n
2, . . . , n
q), the recurrent formula changes into something else, which means for the k
th such value n
k, the recurrent formula changes into
Still an easy problem, isn’t it?
Since f[n] may be quite large, you just need to output f[n] module 10
9 + 7.