Orig Description
Score : 1600 points
Problem StatementThere are N zeros and M ones written on a blackboard.
Starting from this state, we will repeat the following operation: select K of the rational numbers written on the blackboard and erase them, then write a new number on the blackboard that is equal to the arithmetic mean of those K numbers.
Here, assume that N + M - 1 is divisible by K - 1.
Then, if we repeat this operation until it is no longer applicable, there will be eventually one rational number left on the blackboard.
Find the number of the different possible values taken by this rational number, modulo 10^9 + 7.
Constraints
1 ≦ N, M ≦ 2000
2 ≦ K ≦ 2000
N + M - 1 is divisible by K - 1.
InputThe input is given from Standard Input in the following format:
N M K
OutputPrint the number of the different possible values taken by the rational number that will be eventually left on the blackboard, modulo 10^9 + 7.
Sample Input 12 2 2
Sample Output 15
There are five possible values for the number that will be eventually left on the blackboard: \frac{1}{4}, \frac{3}{8}, \frac{1}{2}, \frac{5}{8} and \frac{3}{4}.
For example, \frac{3}{8} can be eventually left if we:
Erase 0 and 1, then write \frac{1}{2}.
Erase \frac{1}{2} and 1, then write \frac{3}{4}.
Erase 0 and \frac{3}{4}, then write \frac{3}{8}.
Sample Input 23 4 3
Sample Output 29
Sample Input 3150 150 14
Sample Output 3937426930
Extracted Specification
Canonicalized Input Description:
An integer N (1 ≤ N ≤ 2000), representing some quantity.
An integer M (1 ≤ M ≤ 2000), representing another quantity.
An integer K (2 ≤ K ≤ 2000).
### Example Input:
```
12
2
2
```
### Function Signature:
Write a function f(N, M, K) that takes in the input.
def f(N: int, M: int, K: int):
'''
N: an integer
M: an integer
K: an integer
'''
Test Case Generator
Here's a test case generator for the given problem statement:
```python
import random
def tcgen():
def find_valid_k(n, m):
possible_ks = [k for k in range(2, 2001) if (n + m - 1) % (k - 1) == 0]
return random.choice(possible_ks)
N = random.randint(1, 2000)
M = random.randint(1, 2000)
K = find_valid_k(N, M)
return N, M, K
# Example usage
if __name__ == "__main__":
for _ in range(5): # Generate 5 test cases
N, M, K = tcgen()
print(f"{N} {M} {K}")
```
Explanation:
1. **Find a Valid \( K \)**:
- A helper function `find_valid_k` is defined to find a valid \( K \) such that \( N + M - 1 \) is divisible by \( K - 1 \).
- It iterates over the range of possible \( K \) values (from 2 to 2000) and collects those that meet the divisibility condition.
- It then randomly selects one from the valid \( K \) values.
2. **Generate \( N \) and \( M \)**:
- Random integers for \( N \) and \( M \) within the given constraints (1 to 2000) are generated.
3. **Generate a Valid \( K \)**:
- Using the helper function, a valid \( K \) is found based on the generated \( N \) and \( M \).
4. **Return the Generated Test Case**:
- The function returns the test case as a tuple \( (N, M, K) \).
This generator ensures that \( N + M - 1 \) is divisible by \( K - 1 \), thereby adhering to the problem constraints.
Extract Arguments
def extract_arguments(fh):
N, M, K = map(int, fh.readline().strip().split())
return N, M, K