問題一覧 > 通常問題

No.1899 L1 Cafe

レベル : / AI推定難易度 : 1900 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 50
作問者 : Shirotsume / テスター : 37zigen ygussany
お気に入りにしたユーザー ProblemId : 7597 / 自分の提出
問題文最終更新日: 2022-04-25 13:25:27
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 338 (順位表) の他の問題:

Problem Statement

Alice lives in a town on an infinitely extending two-dimensional plane. Her home is at the origin, that is, at coordinates $(x, y) = (0, 0)$.

In this town, there are roads represented by the line $x = An$ for every non-negative integer $n$ and the line $y = Bm$ for every non-negative integer $m$. There are no other roads.

Alice wants to choose $1$ point $(x, y)$ in this town and build a cafe there. A candidate location $(x, y)$ for the cafe must satisfy all of the following conditions.

  • $x$ and $y$ are both positive integers.
  • The Manhattan distance from her home $(0, 0)$ is at most $N$. That is, $x + y \leq N$ holds.
  • $(x, y)$ can be reached from her home $(0, 0)$ by traveling only along roads.

How many points are possible as a candidate location $(x, y)$ for the cafe?

You are given $T$ test cases; solve each of them.

Constraints

  • All input values are integers.
  • $1 \leq T \leq 10^5$
  • $2 \leq N \leq 10^9$
  • $1 \leq A \leq 10^9$
  • $1 \leq B \leq 10^9$

Input

The input is given from standard input. The $1$st line is given in the following format.

$T$

Then, $T$ test cases follow, each given in the following format.

$N$ $A$ $B$

Output

Print $T$ lines. On the $i$-th $(1 \leq i \leq T)$ line, print the answer to the $i$-th test case.

It can be proved that under the constraints of this problem, the answer is less than $2^{63}$.

Print a newline at the end.

Sample

Sample 1
Input
5
10 2 3
8 9 10
1200 1 2
31415 92 65
123456789 12345 67890
Output
27
0
719400
12841651
729437374182

$5$ test cases are given.

In the $1$st test case, as shown in the figure below, there are roads represented by the lines $x = 0, x = 2, x = 4, x = 6, \dots$ and $y = 0, y = 3, y = 6, y = 9, \dots$.

For example, $(2, 2)$, $(6, 3)$, and $(1, 9)$ have a Manhattan distance of at most $10$ from her home and can be reached by traveling along roads via routes such as those shown in the figure above, so they satisfy the conditions for building a cafe. There are other coordinates that satisfy the conditions as well, and there are $27$ candidate locations in total.

In the $2$nd test case, there are no coordinates where a cafe can be built. Print $0$. Note that for the coordinates where the cafe is built, both $x, y$ must be positive.

Note that the answer may not fit in a 32bit integer.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。