A Simple Function
Time limit1sMemory limit512 MB
Define f via a Pascal-like recurrence that resets to 0 whenever the sum is divisible by prime M, and answer up to 10^4 queries f(a, b, M) modulo 10^9+7.
- Level
Hard8 of 10
- Topics
- Number theory, Combinatorics, Math, Dynamic programming
- Solved
- No attempts yet
Problem
Let be the set of non-negative integers. The function is defined as follows.
- for all and .
- for all and .
- whenever .
- For , if is not a multiple of , then .
- For , if is a multiple of , then .
For example, and .
Input
The first line contains an integer , the number of test cases. Each of the next lines contains three space-separated integers , , and . For each such line, compute the value of .
You may assume:
- is a prime no greater than .
Output
For each test case, print the answer modulo on its own line.