process.stdin.resume(); process.stdin.setEncoding('ascii'); var input_stdin = ""; var input_stdin_array = ""; var input_currentline = 0; process.stdin.on('data', function (data) { input_stdin += data; }); process.stdin.on('end', function () { input_stdin_array = input_stdin.split("\n"); main(); }); function readLine() { return input_stdin_array[input_currentline++]; } /////////////// ignore above this line //////////////////// function howManyGames(p, d, m, s) { // Return the number of games you can buy if(s
m){ var temp = p-d; p1 = temp<=m?m:temp; }else{ return Math.floor(s/m); } return 1 + howManyGames(p1,d,m,s-p); } function main() { var p_temp = readLine().split(' '); var p = parseInt(p_temp[0]); var d = parseInt(p_temp[1]); var m = parseInt(p_temp[2]); var s = parseInt(p_temp[3]); var answer = howManyGames(p, d, m, s); process.stdout.write("" + answer + "\n"); }