CF BUDDY
← Problems·

1877C · Joyboard

1200 · math, number theory

Problem: Chaneka, a gamer kid, invented a new gaming controller called joyboard. Interestingly, the joyboard she invented can only be used to play one game.

The joyboard has a screen containing n+1n+1 slots numbered from 11 to n+1n+1 from left to right. The n+1n+1 slots are going to be filled with an array of non-negative integers [a1,a2,a3,,an+1][a_1,a_2,a_3,\ldots,a_{n+1}]. Chaneka, as the player, must assign an+1a_{n+1} with an integer between 00 and mm inclusive. Then, for each ii from nn to 11, the value of aia_i will be equal to the remainder of dividing ai+1a_{i+1} (the adjacent value to the right) by ii. In other words, ai=ai+1modia_i = a_{i + 1} \bmod i.

Chaneka wants it such that after every slot is assigned with an integer, there are exactly kk distinct values in the entire screen (among all n+1n+1 slots). How many valid ways are there for assigning a non-negative integer into slot n+1n+1?

Input Format: Each test contains multiple test cases. The first line contains an integer tt (1t21041 \leq t \leq 2\cdot10^4) — the number of test cases. The following lines contain the description of each test case.

The only line of each test case contains three integers nn, mm, and kk (1n1091 \leq n \leq 10^9; 0m1090 \leq m \leq 10^9; 1kn+11 \leq k \leq n+1) — there are n+1n+1 slots, the integer assigned in slot n+1n+1 must not be bigger than mm, and there should be exactly kk distinct values.

Output Format: For each test case, output a line containing an integer representing the number of valid ways for assigning a non-negative integer into slot n+1n+1.

Note: In the first test case, one of the 22 possible ways for Chaneka is to choose an+1=6a_{n+1}=6. If she does that, then:

  • a4=a5mod4=6mod4=2a_4=a_5\bmod 4=6\bmod 4=2
  • a3=a4mod3=2mod3=2a_3=a_4\bmod 3=2\bmod 3=2
  • a2=a3mod2=2mod2=0a_2=a_3\bmod 2=2\bmod 2=0
  • a1=a2mod1=0mod1=0a_1=a_2\bmod 1=0\bmod 1=0
  • a=[0,0,2,2,6]a = [0, 0, 2, 2, 6]
  • There are 33 distinct values.

In the second test case, the 11 possible way for Chaneka is to choose an+1=0a_{n+1}=0. If she does that, then a=[0,0,0]a = [0, 0, 0]. There is only 11 distinct value.

In the third test case, there is no possible way for assigning a non-negative integer into slot n+1n+1.

Sample Cases

Case 1

Input

4
4 6 3
2 0 1
265 265 265
3 10 2

Output

2
1
0
5

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback