Assume 0 < N <= M
Sum = N + M
GCD = G, so that N = x * G, M = y * G and x, y are relatively prime integers > 0
=>
Sum = x * G + y * G = G * (x + y)
Sum / G should also be integer, otherwise no answer
x + y = Sum / G
We need to take smallest x, so that x, y are relatively prime, so x = 1
=> x = 1 => N = G => M = Sum - G
Answer: GCD, Sum - GCD
Test:
1) Solve(12, 4) = 4, 8; GCD(4, 8) = 4; 4 + 8 = 12; OK
2) Solve(12, 5): 12 % 5 > 0 => No Answer; OK
3) Solve(10, 2) = 2, 8; GCD(2, 8) = 2; 2 + 8 = 10; OK

iOS Developer by profession. Interested in UX Design, AI and Robotics. I also enjoy watching random YouTube videos, reading, going out for walks and doing some graphic design on the side.

Assume 0 < N <= M

Sum = N + M

GCD = G, so that N = x * G, M = y * G and x, y are relatively prime integers > 0

=>

Sum = x * G + y * G = G * (x + y)

Sum / G should also be integer, otherwise no answer

x + y = Sum / G

We need to take smallest x, so that x, y are relatively prime, so x = 1

=> x = 1 => N = G => M = Sum - G

Answer: GCD, Sum - GCD

Test:

1) Solve(12, 4) = 4, 8; GCD(4, 8) = 4; 4 + 8 = 12; OK

2) Solve(12, 5): 12 % 5 > 0 => No Answer; OK

3) Solve(10, 2) = 2, 8; GCD(2, 8) = 2; 2 + 8 = 10; OK

Reiterating to this logic in Swift: