Let's assume that all newly played games are victory, since otherwise win rate would fall. So, we need to find minimum such that \frac{p+k}{q+k}\ge \frac{a}{b}. Let's try to solve equation. . So, k\cdot (b-a)\ge q\cdot a-b\cdot p. Now, we have that k\ge \frac{q\cdot a-b\cdot p}{b-a}. Note, that task can also be solved using binary search. It uses following idea: if \frac{p+k}{q+k}\ge \frac{a}{b}, then the answer is at most and otherwise answer is bigger then .