Your answer looks pretty good.
Since all your numbers (i.e. the bases) are positive and not equal to 1, then they should be valid but there is one condition where if p = 0 and q = 0 then r = 0.
This is a special case because you will get r*(p+q) = 0 but p + q is 0 and so you get r*0 = 0 so you need a special condition that if p = 0 and q = 0 then r = 0 as well.
It's just a special case of division by 0 that you have to handle.