P8644 [Lanqiao Cup 2016 National B] Robot Tower

Description

The robot cheerleading team on Planet X has two kinds of uniforms, A and B. This time, they are performing by building a robot tower. For example: ``` A B B A B A A A B B B B B A B A B A B B A ``` The team’s tower-building rules are: A can only stand on the shoulders of AA or BB. B can only stand on the shoulders of AB or BA. Your task is to help the team compute, given the numbers of A and B, how many different tower patterns can be formed.

Input Format

One line with two integers $M$ and $N$, separated by a space ($0 < M, N < N + M \leq 231$, and it is guaranteed that there exists $k \in \mathbb{N}$ such that $N + M = \frac{k(k-1)}{2}$), representing the number of A and the number of B, respectively.

Output Format

Output one integer, indicating the number of different patterns that can be produced.

Explanation/Hint

Time limit: 1 second, 256 MB. Lanqiao Cup 2016, 7th edition. Translated by ChatGPT 5