Problem:


Wire

I am a craftsman specialized in interior works. A customer asked me to perform wiring work on a wall whose entire rectangular surface is tightly pasted with pieces of panels. The panels are all of the same size (2 m in width, 1 m in height) and the wall is filled with an x (horizontal) by y (vertical) array of the panels. The customer asked me to stretch a wire from the left top corner of the wall to the right bottom corner whereby the wire is tied up at the crossing points with the panel boundaries (edges and vertexes) as shown in the figure. There are nine tied-up points in the illustrative figure shown below.

 

  
    Fig: The wire is tied up at the edges and vertexes of the panels (X: 4 panels, Y: 6 panels)

    

  Write a program to provide the number of points where the wire intersects with the panel boundaries.
Assume that the wire and boundary lines have no thickness.

Input

  The input is given in the following format.

x y

A line of data is given that contains the integer number of panels in the horizontal direction x (1 ≤ x ≤ 1000) and those in the vertical direction y (1 ≤ y ≤ 1000). 

Output

  Output the number of points where the wire intersects with the panel boundaries.

Sample Input 1

4 4

Sample Output 1

5

Sample Input 2

4 6

Sample Output 2

9



Sample input:
4 4


Sample output:
5

Submission status: Wrong Answer

Solution code:
x, y = map(int, input().split())
if x == y:
    print(x+1)
else:
    print(min(x, y ) + 1 + abs(x - y) * 2)

Submission status: Accepted

Solution code:
print((lambda x : int(x[0]) + int(x[1]) + 1 - (lambda *x, f=lambda f, x, y: f(f, y, x % y) if y else x: f(f, *x))(int(x[0]),int(x[1])))(input().split()))

Submission status: Accepted

Solution code:
print((lambda x : int(x[0]) + int(x[1]) + 1 - (lambda *x, f=lambda f, x, y: f(f, y, x % y) if y else x: f(f, *x))(int(x[0]),int(x[1])))(input().split()))

Submission status: Accepted

Solution code:
print((lambda x:int(x[0])+int(x[1])+1-(lambda*x,f=lambda f,x,y:f(f,y,x%y) if y else x:f(f,*x))(int(x[0]),int(x[1])))(input().split()))

Submission status: Accepted

Solution code:
import math
x,y=list(map(int,input().split()))
print(x+y-math.gcd(x,y)+1)

Submission status: Accepted

Solution code:
def gcd(p,q):
      if p<q:
            return gcd(q,p)
      if p%q==0:
            return q
      else:
            return gcd(q,p%q)

x,y = map(int,list(input().split(" ")))
print(x+y+1-gcd(x,y))

Submission status: Accepted

Solution code:
x, y = map(int, input().split())
def eu(x, y):
    p, q = max(x, y), min(x, y)
    while p % q != 0:p, q = q, p % q
    return q
print(x + y - eu(x, y) + 1)

Submission status: Accepted

Solution code:
from math import gcd
x, y = map(int, input().split())
print(x + 1 + y + 1 - gcd(x, y) - 1)

Submission status: Accepted

Solution code:
import math

a, b = map(int, input().split())
g = math.gcd(a, b)
a1, b1 = a/g, b/g
print(int((a1-1+b1)*g+1))

Submission status: Accepted

Solution code:
def GCD(M, N) :
    while True :
        if N < M :
            N, M = M, N
        amari = N % M
        if amari == 0 :
            break
        else :
            N, M = M, amari
    return M

x, y = map(int, input().split()) 
gcd = GCD(x, y)
x = x / gcd
y = y / gcd
print(int(x-1 + y-1 + 1) * gcd + 1)

Submission status: Accepted

Solution code:
import math
x,y = list(map(int, input().split()))
gc = math.gcd(x,y)
print(x+y - gc + 1)

Submission status: Accepted

Solution code:
import math
a,b = map(int,input().split())
print(a+b-(math.gcd(a,b))+1)

Submission status: Accepted

Solution code:
from math import gcd
x,y=map(int,input().split())
print(x+y-gcd(x,y)+1)

Submission status: Accepted

Solution code:
def gcd(m, n):
    r = m % n
    return gcd(n, r) if r else n
x, y = map(int, input().split())
g = gcd(x, y)
print(((x // g - 1) + (y // g - 1) + 1) * g + 1)

Submission status: Accepted

Solution code:

def calGCD(x,y):
    while(y > 0):
        x, y = y, x % y
    return x

x,y = [int(i) for i in input().split()]
d = calGCD(x,y)

ans = (x-1) + (y-1) + 2 - (d-1)
print(ans)

Submission status: Accepted

Solution code:
import math
x,y=map(int,input().split())

k=math.gcd(x,y)
if k==1:
    print(x+y)
else:
    m=2*x//k
    print(x+y+1-2*x//m)

Submission status: Accepted

Solution code:
import math

x, y = map(int, input().split())
g = math.gcd(x, y)
print(x+y-g+1)

Submission status: Accepted

Solution code:
import math
def intersection(x,y):
    g = math.gcd(x, y)
    if g == 1:
        return x + y
    return intersection(x//g, y//g) * g - (g-1)
print(intersection(*map(int, input().split())))

Submission status: Accepted

Solution code:
il = lambda: list(map(int, input().split()))
ils = lambda n, s="int(input())": [eval(s) for _ in range(n)]
def gcd(a, b):
    if a < b: return gcd(b, a)
    if b == 0: return a
    return gcd(b, a%b)

x, y = il()
a = gcd(x, y)
print(x+y-a+1)

Submission status: Accepted

Solution code:
import fractions
a,b = map(int,input().split())
print(a + b + 1 -fractions.gcd(a, b))

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
cnt = 0
for x in range(0, a*2+1, 2):
	if((b*x) % (2*a) == 0):
		cnt += 1
print(a + b - cnt + 2)

Submission status: Runtime Error

Solution code:
print((lambda x,y : x + y + 1 - (lambda *x, f=lambda f, x, y: f(f, y, x % y) if y else x: f(f, *x))(x,y))(int(input()),int(input())))