Logo
(追記) (追記ここまで)

15471번 - A Simple Function 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB36181562.500%

문제

A function f : N3 → N where N stands for the set of non-negative integers, is defined as follows.

  • 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.

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.

제한

예제 입력 1

2
2 1 2
4 2 5

예제 출력 1

0
6

힌트

출처

ICPC > Regionals > Asia Pacific > Taiwan > Taiwan Online Programming Contest > TOPC 2017 F번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /