N,X = map(int, input().split())
print(N)
print(X)

def para(a,b):
    if a > b:
        return a+b + para(b,a-b)
    if a < b:
        return 2*a + para(a,b-a)
    if a == b:
        return 3*a
print(X+para(X,N-X))