题库练习 Multicolored Markers
← 上一题 下一题 →

A12036 | Multicolored Markers

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

There is an infinite board of square tiles. Initially all tiles are white.

Vova has a red marker and a blue marker. Red marker can color $a$ tiles. Blue marker can color $b$ tiles. If some tile isn't white then you can't use marker of any color on it. Each marker must be drained completely, so at the end there should be exactly $a$ red tiles and exactly $b$ blue tiles across the board.

Vova wants to color such a set of tiles that:

- they would form a rectangle, consisting of exactly $a+b$ colored tiles;
- all tiles of at least one color would also form a rectangle.

Here are some examples of correct colorings:

![](/uploads/acgo/image/aeaf812fbeea39d1_033985e545e8.jpeg)Here are some examples of incorrect colorings:

![](/uploads/acgo/image/9086ab8381060195_fb3230cb43c9.jpeg)Among all correct colorings Vova wants to choose the one with the minimal perimeter. What is the minimal perimeter Vova can obtain?

It is guaranteed that there exists at least one correct coloring.

输入格式

A single line contains two integers $a$ and $b$ ( $1 \le a, b \le 10^{14}$ ) — the number of tiles red marker should color and the number of tiles blue marker should color, respectively.

输出格式

Print a single integer — the minimal perimeter of a colored rectangle Vova can obtain by coloring exactly $a$ tiles red and exactly $b$ tiles blue.

It is guaranteed that there exists at least one correct coloring.

输入输出样例

输入 #1
4 4
输出 #1
12
输入 #2
3 9
输出 #2
14
输入 #3
9 3
输出 #3
14
输入 #4
3 6
输出 #4
12
输入 #5
506 2708
输出 #5
3218
C++ 编辑器
输入
输出