#include #include #include #include #include #include #include int howManyGames(int p, int d, int m, int s) { // Return the number of games you can buy int number_of_games = 0; int total_cost = 0; int current_cost = p; while(1) { total_cost+=current_cost; if(total_cost > s) break; number_of_games++; if(current_cost > m) { current_cost-=d; if(current_cost < m) { current_cost = m; } } else current_cost = m; //printf("%d ", current_cost); } return number_of_games; } int main() { int p; int d; int m; int s; scanf("%i %i %i %i", &p, &d, &m, &s); int answer = howManyGames(p, d, m, s); printf("%d\n", answer); return 0; }