Linear Recurrence RNG
Time limit15sMemory limit512 MB
Given the first k terms and coefficients of a linear recurrence and a huge index N, compute the N-th term modulo 104857601.
- Level
Hard8 of 10
- Topics
- Math, Divide and conquer, Number theory
- Solved
- No attempts yet
Problem
You are writing a random number generator (RNG) for a lottery auto-submit program. The generator builds a sequence from the linear recurrence below.
Given and , the initial terms , and the coefficients , write a program that computes .
Input
The first line contains and , separated by a space. (, )
The second line contains , separated by spaces.
The third line contains , separated by spaces. ()
Output
Print on the first line. is always smaller than 104857601.