This is a generalization of Stopping for lunch
Abe and Ben are on a road trip, and stop at a roadside picnic table for lunch. Abe has P sandwiches. Bert has Q sandwiches. Cal comes along and asks if they would share the sandwiches between the three of them. And they did, each got (P+Q)/3 sandwiches. When Cal is finished he leaves P+Q dollars to pay for the sandwiches.
Abe and Ben thereafter divide the money according to the ratio of the sandwiches each of them gave to Cal.
(For example, if (P, Q) = (5, 3), then Abe gives 5-8/3=7/3 sandwiches and, Ben gives 3 -8/3=1/3 sandwiches to Cal. Therefore, the 8 dollars which has been contributed by Cal should be divided in the ratio 7:1, so that Abe receives 7 dollars and, Ben receives 1 dollar.)
It is observed that Abe’s share of the money is precisely R times that of Ben.
Given that each of P, Q and R is a positive integer with Q < P < 2Q:
(i) Express P in terms of Q whenever, gcd(P, Q) = 1 and R = 1 (mod 3)
(ii) If (P, R) =(Q+m, m+1), then determine Q in terms of m.