from math import floor
N, X = [int(x) for x in input().split()]

print(N, X)

x0 = N
x1 = X
x2 = x0-x1
L = 2*X
c = 1
while x2 > 0:
	k = floor(x0/(x1/2))-1
	L += x1*k
	x0, x1, x2 = (x1, x2, x0-x1)

print(L)