Scanner scan = new Scanner(System.in) int p = scan.nextInt() int d = scan.nextInt() int m = scan.nextInt() int s = scan.nextInt() int numGames = 0 int totalCost = 0 int currentCost = p; while (totalCost < s) { if (totalCost + currentCost <= s) { numGames++ totalCost += currentCost currentCost -= d if (currentCost < m) { currentCost = m } } else { break } } println numGames