Orig Description
Score : 600 points
Problem StatementWe have an integer sequence A of length N, where A_1 = X, A_{i+1} = A_i + D (1 \leq i < N ) holds.
Takahashi will take some (possibly all or none) of the elements in this sequence, and Aoki will take all of the others.
Let S and T be the sum of the numbers taken by Takahashi and Aoki, respectively. How many possible values of S - T are there?
Constraints
-10^8 \leq X, D \leq 10^8
1 \leq N \leq 2 \times 10^5
All values in input are integers.
InputInput is given from Standard Input in the following format:
N X D
OutputPrint the number of possible values of S - T.
Sample Input 13 4 2
Sample Output 18
A is (4, 6, 8).
There are eight ways for (Takahashi, Aoki) to take the elements: ((), (4, 6, 8)), ((4), (6, 8)), ((6), (4, 8)), ((8), (4, 6))), ((4, 6), (8))), ((4, 8), (6))), ((6, 8), (4))), and ((4, 6, 8), ()).
The values of S - T in these ways are -18, -10, -6, -2, 2, 6, 10, and 18, respectively, so there are eight possible values of S - T.
Sample Input 22 3 -3
Sample Output 22
A is (3, 0). There are two possible values of S - T: -3 and 3.
Sample Input 3100 14 20
Sample Output 349805
Extracted Specification
An integer N (1 ≤ N ≤ 2 x 10^5), representing some quantity or size.
An integer X (-10^8 ≤ X ≤ 10^8).
An integer D (-10^8 ≤ D ≤ 10^8).
### Example Input:
```
3
4
2
```
### Function Signature:
Write a function f(N, X, D) that takes in the input.
def f(N: int, X: int, D: int):
'''
N: an integer
X: an integer
D: an integer
'''
Test Case Generator
To create a test case generator for the problem statement provided, we need to ensure that the generated inputs adhere to the constraints and generate valid sequences. Here's a Python function to generate randomized test cases:
```python
import random
def tcgen():
# Constraints
MIN_X_D = -10**8
MAX_X_D = 10**8
MIN_N = 1
MAX_N = 2 * 10**5
# Generate random values within the constraints
N = random.randint(MIN_N, MAX_N)
X = random.randint(MIN_X_D, MAX_X_D)
D = random.randint(MIN_X_D, MAX_X_D)
return N, X, D
# Example usage:
for _ in range(5): # Generate 5 test cases
print(tcgen())
```
This function generates random values for \( N \), \( X \), and \( D \) within the specified constraints. You can call this function multiple times to generate different test cases. The results will be tuples of three values representing \( N \), \( X \), and \( D \), which can be directly used as test cases for the problem.
Here's how it works:
- \( N \) is randomly generated between 1 and 200,000.
- \( X \) and \( D \) are randomly generated between -100,000,000 and 100,000,000.
### Example Output
Running the function multiple times might give output like this:
```
(193045, 58474524, 2148231)
(36521, -98127463, 47281945)
(146789, 567234, -98765432)
(100000, -100000000, 100000000)
(200000, -12345678, 87654321)
```
These outputs can be used directly as inputs to the problem statement.
Extract Arguments
def extract_arguments(fh):
N, X, D = map(int, fh.readline().strip().split())
return N, X, D