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 × 10^5), representing some quantity or size.
An integer X (-10^8 ≤ X ≤ 10^8), representing some initial value.
An integer D (-10^8 ≤ D ≤ 10^8), representing some difference value.
### Example Input:
```
3
100
14
20
```
### 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
Here's a test case generator for the given problem statement:
```python
import random
def tcgen():
N = random.randint(1, 2 * 10**5)
X = random.randint(-10**8, 10**8)
D = random.randint(-10**8, 10**8)
return N, X, D
# Example usage:
N, X, D = tcgen()
print(f"{N} {X} {D}")
```
This function generates a random test case for your problem statement by:
1. Generating \(N\) as a random integer between 1 and \(2 \times 10^5\).
2. Generating \(X\) as a random integer between \(-10^8\) and \(10^8\).
3. Generating \(D\) as a random integer between \(-10^8\) and \(10^8\).
You can use the `tcgen` function to generate diverse test cases, which can then be used to test the solution to the problem. The `print` statement at the end demonstrates how to output the generated test case in the required format.
Extract Arguments
def extract_arguments(fh):
N, X, D = map(int, fh.readline().strip().split())
return N, X, D
# if __name__ == "__main__":
# input_path = sys.argv[1]
# with open(input_path, 'r') as fh:
# N, X, D = extract_arguments(fh)
# f(N, X, D)