Problem p02979 - Generation 3

Orig Description

Score : 1600 points
Problem StatementThere is a blackboard on which all integers from -10^{18} through 10^{18} are written, each of them appearing once. Takahashi will repeat the following sequence of operations any number of times he likes, possibly zero:
Choose an integer between 1 and N (inclusive) that is written on the blackboard. Let x be the chosen integer, and erase x.
If x-2 is not written on the blackboard, write x-2 on the blackboard.
If x+K is not written on the blackboard, write x+K on the blackboard.
Find the number of possible sets of integers written on the blackboard after some number of operations, modulo M.
We consider two sets different when there exists an integer contained in only one of the sets.
Constraints
1 \leq K\leq N \leq 150
10^8\leq M\leq 10^9
N, K, and M are integers.
InputInput is given from Standard Input in the following format:
N K M
OutputPrint the number of possible sets of integers written on the blackboard after some number of operations, modulo M.
Sample Input 13 1 998244353
Sample Output 17
Every set containing all integers less than 1, all integers greater than 3, and at least one of the three integers 1, 2, and 3 satisfies the condition. There are seven such sets.
Sample Input 26 3 998244353
Sample Output 261
Sample Input 39 4 702443618
Sample Output 3312
Sample Input 417 7 208992811
Sample Output 4128832
Sample Input 5123 45 678901234
Sample Output 5256109226

Extracted Specification

An integer N (1 ≤ N ≤ 150), representing some quantity.
An integer K (1 ≤ K ≤ N), representing another quantity.
An integer M (10^8 ≤ M ≤ 10^9), representing a modulus value.

### Example Input:
```
13 1 998244353
```

### Function Signature:
Write a function f(N, K, M) that takes in the input.
def f(N: int, K: int, M: int):
    '''
    N: an integer
    K: an integer
    M: an integer
    '''

Test Case Generator

To generate test cases for this problem, we need to take into account the constraints provided. Here's a Python function to generate random test cases based on the given constraints:

```python
import random

def tcgen():
    # Define the constraints
    min_N = 1
    max_N = 150
    min_K = 1
    min_M = 10**8
    max_M = 10**9
    
    # Generate random values within the constraints
    N = random.randint(min_N, max_N)  # N between 1 and 150
    K = random.randint(min_K, N)      # K between 1 and N (inclusive)
    M = random.randint(min_M, max_M)  # M between 10^8 and 10^9
    
    return f"{N} {K} {M}"

# Example of generating a test case
print(tcgen())
```

This function randomly generates values for \(N\), \(K\), and \(M\) within the specified constraints and returns them in the required format. You can run this function multiple times to generate different test cases. Here’s a breakdown of the approach:

1. **N** is generated between 1 and 150.
2. **K** is generated between 1 and \(N\) (inclusive).
3. **M** is generated between \(10^8\) and \(10^9\).

Each time you call `tcgen()`, you'll get a new set of values for \(N\), \(K\), and \(M\) adhering to the constraints. For instance:

```python
# Example output
print(tcgen())  # "74 39 423451789"
print(tcgen())  # "120 120 934567890"
print(tcgen())  # "5 3 100000000"
```

These outputs can be used as input for your competitive programming problem.

Extract Arguments

def extract_arguments(fh):
    N, K, M = map(int, fh.readline().strip().split())
    return N, K, M