Programming Problem: Interchange

problem

Dear ACM Solvers Today I am giving a simple and interesting Number theory Problem for you though I am not sure whether it should be treated as Number theory or ad-hoc type problem. You know better 🙂

Assume a 2 digit number xy=75. If the position of digit have been interchanged it goes to yx=57.
Now the difference between the 2 numbers is z = xy-yx = 18. If you play with some 2 digit numbers you will get an interesting sequence.
In this problem you will be given x and z. You have to find y.

Sample Input:
X Z
7 18
4 36

Output:
Y
5
0

Constraints: 0<=y<=x<= 9 No search or loop operation should be used in source code. It’s really interesting problem if you can catch the simple equation. Best of luck 🙂 Note: If you solve it please send code to dedicated_soul@yahoo.com

You may also like