cswork / OA打开练习工作台

MicrosoftOA #62

Side Largest Square

估计中等可在线判题

考点(AI 标注)位运算二分查找

There are m tiles of size 1×1 and n tiles of size 2×2. You may choose some of the tiles to form a square on a grid with no overlaps and no gaps. Find the maximum integer side length.

This site uses a standard input/output protocol.

输入格式

One line m n, 0≤m,n≤10⁹. The original range gives a lower bound of 1, but the source's examples explicitly include 0, so this site also keeps the zero-tile cases.

输出格式

Output a single integer, the answer.

样例 1

输入:

8 0

输出:

2

样例 2

输入:

4 3

输出:

4

样例 3

输入:

0 18

输出:

8

样例说明

Example 1: 8 unit tiles can only form side length 2, since they are not enough for 9 cells. Example 2: three large tiles plus four small tiles fill a 4×4 square. Example 3: using only large tiles, the largest even side length is 8, which uses 16 tiles and leaves 2.