問題一覧 > 通常問題

No.886 Direct

レベル : / AI推定難易度 : 2200 / 実行時間制限 : 1ケース 4.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 62
作問者 : QCFium / テスター : tempura_pp
お気に入りにしたユーザー ProblemId : 3267 / 自分の提出
問題文最終更新日: 2019-09-02 13:42:12
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 223 (順位表) の他の問題:

Problem Statement

The time limit for this problem is 4 seconds.

$HW$ points are arranged in an evenly spaced $H \times W$ grid.
Find the number of line segments that connect 2 distinct points among them and do not pass through any point other than those 2 points.
Here, two line segments are considered different if they are different as geometric figures.
Also, since the answer can get fairly large, output the answer modulo $10^9+7$.

Input

$H \hspace{7pt} W$

$1 \le H \le 3 \times 10^6$
$1 \le W \le 3 \times 10^6$
$H$ and $W$ are integers.

Output

Output the number of line segments satisfying the conditions in the problem statement, modulo $10^9+7$.
Print a newline at the end.

Sample

Sample 1
Input
2 2
Output
6

In this case, every line segment connecting a pair of 2 distinct points satisfies the condition.

Sample 2
Input
1 1
Output
0

There are no line segments connecting 2 distinct points in the first place.

Sample 3
Input
2 3
Output
13

The 6 points are arranged as follows.

. . .
. . .

All $3 \times 3 = 9$ line segments connecting the upper row and the lower row satisfy the condition. Among the line segments connecting points within the upper row, only the $2$ connecting adjacent points satisfy the condition, and the same applies to the lower row.
Therefore, $9 + 2 + 2 = 13$ line segments satisfy the condition.

Sample 4
Input
41279 3235
Output
0

Output the answer modulo $10^9+7$.

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