#P2660. Minimum Energy for Square Planting

    ID: 15925 Type: Default 1000ms 256MiB

Minimum Energy for Square Planting

Minimum Energy for Square Planting

Problem description: A huge rectangular field is given with dimensions n and m. However, each time, only one square plot can be planted, and the energy cost for planting a square plot of side s is its perimeter, i.e., (4s). Once a square is planted, that part of the field cannot be used again. zzc, who is very lazy and wants to conserve energy, wants to cover the entire field with non-overlapping squares using the minimum total energy. It can be proven that the minimum energy required is (4\times (n + m - \gcd(n, m))). Your task is to compute this value for given n and m.

inputFormat

The input consists of two integers n and m (1 (\leq) n, m (\leq) 10^9), representing the dimensions of the rectangular field.

outputFormat

Output a single integer — the minimum total energy required, which equals (4\times (n + m - \gcd(n, m))).

sample

1 1
4