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:
Here are some examples of incorrect colorings:
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.
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:
Here are some examples of incorrect colorings:
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.
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
The first four examples correspond to the first picture of the statement.
Note that for there exist multiple correct colorings for all of the examples.
In the first example you can also make a rectangle with sides $1$ and $8$ , though its perimeter will be $18$ which is greater than $8$ .
In the second example you can make the same resulting rectangle with sides $3$ and $4$ , but red tiles will form the rectangle with sides $1$ and $3$ and blue tiles will form the rectangle with sides $3$ and $3$ .
Note that for there exist multiple correct colorings for all of the examples.
In the first example you can also make a rectangle with sides $1$ and $8$ , though its perimeter will be $18$ which is greater than $8$ .
In the second example you can make the same resulting rectangle with sides $3$ and $4$ , but red tiles will form the rectangle with sides $1$ and $3$ and blue tiles will form the rectangle with sides $3$ and $3$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted