[BOJ 15471] A Simple Function
View as PDF
Submit solution
Assembly, Awk, C, C++, Java, Pascal, Perl, Python, Sed, Text
Points:
4
Time limit:
1.0s
Memory limit:
512M
Problem types
Allowed languages
A function f : N3 → N where N stands for the set of non-negative integers, is defined as follows.</p>
- f(i, 0, M) = 1, for all i and M.
- f(i, i, M) = 1, for all i and M.
- f(i, x, M) = 0, for all i < x.
- f(i, x, M) = f(i − 1, x − 1, M) + f(i − 1, x, M), if f(i − 1, x − 1, M) + f(i − 1, x, M) is NOT a multiple of M, for all 0 < x < i.
- f(i, x, M) = 0, if f(i − 1, x − 1, M) + f(i − 1, x, M) is a multiple of M, for all 0 < x < i.
For example, f(2, 1, 2) = 0 and f(4, 2, 5) = 6.
입력 형식
The first line of the input contains an integer T, the number of test cases. T lines follow, one line per test case consisting of three space-separated integers a, b and M indicating that the value of f(a, b, M) is to be computed.</p>
You may assume:
- 1 ≤ T ≤ 104
- 0 ≤ a < 231
- 0 ≤ b < 231
- M ≤ 10000 is a prime
For each test case, output a single integer which denotes your answer modulo 109 + 7 in a line.
예제 입력
2
2 1 2
4 2 5
예제 출력
0
6
Comments