CF1029F.Multicolored Markers

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 aa tiles. Blue marker can color bb 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 aa red tiles and exactly bb blue tiles across the board.

Vova wants to color such a set of tiles that:

  • they would form a rectangle, consisting of exactly a+ba+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 aa and bb ( 1a,b10141 \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 aa tiles red and exactly bb 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
    

说明/提示

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 11 and 88 , though its perimeter will be 1818 which is greater than 88 .

In the second example you can make the same resulting rectangle with sides 33 and 44 , but red tiles will form the rectangle with sides 11 and 33 and blue tiles will form the rectangle with sides 33 and 33 .

首页