fork(1) download
  1. from math import gcd
  2.  
  3. while True :
  4. try :
  5. XY = [int(x) for x in input().split()]
  6. if XY[0] == XY[1] :
  7. print(4)
  8. else :
  9. FPB = gcd(XY[0], XY[1])
  10. print((XY[0] // FPB) * 2 + (XY[1] // FPB) * 2)
  11. except EOFError :
  12. pass# your code goes here
Time limit exceeded #stdin #stdout 5s 27712KB
stdin
2 2
3 3
2 5
8 3
76 50
stdout
4
4
14
22
126