#P8644. [蓝桥杯 2016 国 B] 机器人塔

[蓝桥杯 2016 国 B] 机器人塔

Problem 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 MM and NN, separated by a space (0<M,N<N+M2310 < M, N < N + M \leq 231, and it is guaranteed that there exists kNk \in \mathbb{N} such that N+M=k(k1)2N + 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.

1 2
3
3 3
4

Hint

Time limit: 1 second, 256 MB. Lanqiao Cup 2016, 7th edition.

Translated by ChatGPT 5