function next(b, c) { for (var d = c / b * 100 | 1, a = 1; a++;) if (((c + a) / (b + a) * 100 | 0) >= d) return a }; var all_b = 993, pobed = 519,n = next(all_b, pobed); alert(n)