/
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 133 点
問題文
高橋君は、一直線に並んだ N 個のチェックポイントを管理する警備員です。
チェックポイントは左から順に 1, 2, \ldots, N と番号が付けられており、隣り合うチェックポイント間を移動するのにちょうど 1 秒かかります。高橋君の待機所はチェックポイント N にあります。
異常検知のアラームが鳴ると、高橋君は待機所(チェックポイント N)を出発し、チェックポイントを N, N-1, \ldots, 1 の順にたどってチェックポイント 1 まで移動します。その後、折り返してチェックポイントを 1, 2, \ldots, N の順にたどり、待機所(チェックポイント N)まで戻ります。各チェックポイントでの確認作業や折り返しにかかる時間は 0 秒とします。したがって、1 回のパトロールにかかる移動時間は 2(N-1) 秒です。
高橋君は必ず待機所に戻ってから次のパトロールに出発します。M 回のパトロールはすべて同じ経路・同じ移動時間で行われます。
ある日、アラームが M 回鳴り、高橋君は M 回の往復パトロールを行いました。高橋君がこの日の M 回のパトロールにおける移動時間の合計(秒)を求めてください。ただし、パトロール間の待機時間は含みません。
制約
- 1 \leq N \leq 10^9
- 1 \leq M \leq 10^9
- 入力はすべて整数
入力
N M
チェックポイントの数を表す整数 N と、アラームが鳴った回数(パトロールの回数)を表す整数 M が、スペース区切りで 1 行に与えられる。
出力
高橋君が移動に費やした合計時間(秒)を整数で 1 行に出力してください。なお、答えは 2 \times 10^{18} 程度の大きさになることがあります。
入力例 1
3 1
出力例 1
4
入力例 2
5 4
出力例 2
32
入力例 3
1000000000 1000000000
出力例 3
1999999998000000000
Score : 133 pts
Problem Statement
Takahashi is a security guard who manages N checkpoints arranged in a straight line.
The checkpoints are numbered 1, 2, \ldots, N from left to right, and it takes exactly 1 second to move between adjacent checkpoints. Takahashi's station is at checkpoint N.
When an anomaly detection alarm sounds, Takahashi departs from his station (checkpoint N) and travels through the checkpoints in the order N, N-1, \ldots, 1 until he reaches checkpoint 1. He then turns around and travels through the checkpoints in the order 1, 2, \ldots, N, returning to his station (checkpoint N). The time required for inspection at each checkpoint and for turning around is 0 seconds. Therefore, the travel time for one patrol is 2(N-1) seconds.
Takahashi always returns to his station before departing for the next patrol. All M patrols follow the same route and take the same travel time.
One day, the alarm sounded M times, and Takahashi performed M round-trip patrols. Find the total travel time (in seconds) for Takahashi's M patrols that day. Note that waiting time between patrols is not included.
Constraints
- 1 \leq N \leq 10^9
- 1 \leq M \leq 10^9
- All inputs are integers
Input
N M
An integer N representing the number of checkpoints and an integer M representing the number of times the alarm sounded (the number of patrols) are given on a single line, separated by a space.
Output
Print the total time (in seconds) Takahashi spent traveling as an integer on a single line. Note that the answer can be as large as approximately 2 \times 10^{18}.
Sample Input 1
3 1
Sample Output 1
4
Sample Input 2
5 4
Sample Output 2
32
Sample Input 3
1000000000 1000000000
Sample Output 3
1999999998000000000