#P8177. 「EZEC-11」等差数列

「EZEC-11」等差数列

Description

You are given an arithmetic progression xx of length nn, with first term aa and common difference dd.

Choose any two numbers xi,xjx_i, x_j from xx (iji\neq j), and they must satisfy at the same time:

  • xi+xjx_i + x_j is even.
  • xi+xj2\frac{x_i + x_j}{2} is not in xx.

Then you may add xi+xj2\frac{x_i + x_j}{2} into xx. This is called one operation.

Note: Newly added numbers can also be chosen.

What is the maximum number of operations you can perform?

Input Format

This problem has multiple sets of testdata.

The first line contains a positive integer TT, the number of testdata sets.

For each testdata set, one line contains three integers n,a,dn, a, d.

Output Format

For each testdata set, output one integer per line, the maximum number of operations.

2
3 1 1
2 2 2
0
1

Hint

[Sample 1 Explanation]

For the first set of testdata, x=[1,2,3]x=[1,2,3], so no operation can be performed.

For the second set of testdata, x=[2,4]x=[2,4]. You can choose 22 and 44, and add 2+42=3\frac{2+4}{2}=3 into the sequence.

[Constraints and Notes]

This problem uses bundled tests.

  • Subtask 1 (10 points): d=1d=1.
  • Subtask 2 (10 points): n=2n=2.
  • Subtask 3 (30 points): T10T\le 10, n×d103n\times d\le 10^3, a=0a=0.
  • Subtask 4 (50 points): no special restrictions.

For 100%100\% of the data, 1T1051\le T\le 10^5, 2n1092\le n\le 10^9, 109a109-10^9\le a\le 10^9, 1d1091\le d\le 10^9.

Translated by ChatGPT 5