The greatest whole humber like that is 987654321
you have to use intercept theorem, also known as Thales's theorem to slove this problem
The answer is r = p/2n - x/n
Assuming your solving for y:
py+7=6y+q
-6y -7 -6y -7
(p-6)y = q-7
divide both sides by p-6
y=(q-7)/(p-6)