CF1029F.Multicolored Markers

普及+/提高

通过率:0%

时间限制:3.00s

内存限制:256MB

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.

有一个无限大的正方形瓷砖棋盘,初始时所有瓷砖均为白色。

沃瓦有一支红色记号笔和一支蓝色记号笔。红色记号笔可涂色 aa 块瓷砖,蓝色记号笔可涂色 bb 块瓷砖。若某块瓷砖已非白色,则不能再用任何颜色的记号笔在其上涂色。每支记号笔必须完全用尽,因此最终棋盘上恰好有 aa 块红色瓷砖和 bb 块蓝色瓷砖。

沃瓦希望涂色一组瓷砖,满足以下条件:

  • 这些瓷砖构成一个矩形,且该矩形中恰好包含 a+ba+b 块已涂色瓷砖;
  • 至少一种颜色的所有瓷砖自身也构成一个矩形。

以下是若干正确涂色方案的示例:

以下是若干错误涂色方案的示例:

在所有正确的涂色方案中,沃瓦希望选择周长最小的一种。请问沃瓦所能达到的最小周长是多少?

保证至少存在一种正确的涂色方案。

输入格式

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

一行包含两个整数 aa 和 bb(1≤a,b≤10141 \le a, b \le 10^{14}),分别表示红色标记笔需要涂色的瓷砖数量和蓝色标记笔需要涂色的瓷砖数量。

输出格式

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.

输出一个整数——Vova 通过恰好将 aa 个方格涂成红色、恰好将 bb 个方格涂成蓝色所能得到的彩色矩形的最小周长。

保证至少存在一种合法的涂色方案。

输入输出样例

  • 输入#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.

前四个示例对应题目描述中的第一张图片。

注意:所有示例均存在多种正确的染色方案。

在第一个示例中,你也可以构造一个边长为 11 和 88 的矩形,但其周长为 1818,大于 88。

在第二个示例中,你仍可得到相同的最终矩形(边长为 33 和 44),但红色方块构成一个边长为 11 和 33 的矩形,而蓝色方块构成一个边长为 33 和 33 的矩形。

输入解题思路,AI测评打分。不知道怎么写?

首页