問題一覧 > 通常問題

No.333 Counting Kadomatsu Sequences

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 483
作問者 : nmnmnmnmnmnmnm
お気に入りにしたユーザー ProblemId : 935 / 自分の提出
問題文最終更新日: 2026-06-25 06:25:58
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 129 (順位表) の他の問題:

Problem Statement

A Kadomatsu sequence is defined as follows: when three integers are arranged as A, B, C from left to right,
all the values are distinct and the second largest integer among A, B, C is either A or C.

D-kun obtained one Kadomatsu sequence whose three numbers are each one of the positive integers from 1 to 2000000000.
However, D-kun lost the rightmost number and does not remember it.
Given the left number A and the middle number B, count how many possible values there are for the right number C.

Input

A B

A is the left number of the Kadomatsu sequence, and B is the middle number of the Kadomatsu sequence. $1\le A,B \le 2000000000= 2 \times 10^9$.
Since A and B were originally part of a Kadomatsu sequence, there is no input with an impossible configuration such as A=B.

Output

Output on one line the number of possibilities that answers the problem.
Do not forget the newline at the end.

Sample

Sample 1
Input
2 3
Output
1

For it to be a Kadomatsu sequence, the right number must be 1, so there is only 1 possibility.

Sample 2
Input
2 1
Output
1999999998

The 1999999998 values from 3 to 2000000000 are possible.

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