function solution(a, b, n) {
let answer = 0;
while (n > 1) {
if (n < a) {
break;
}
let bottle = Math.floor(n / a) * b;
answer += bottle;
n = bottle + (n % a);
}
return answer;
}
solution = (a, b, n) => Math.floor(Math.max(n - b, 0) / (a - b)) * b
// ------------
function solution(a, b, n){
return Math.floor(Math.max(n - b, 0) / (a - b)) * b;
}
예를 들어 a,b,n이 5,2,20일 때
5병씩 4번을 가져가면 각각 2병씩 8병이 된다.
따라서, 반납했을 때의 가치는 Math.floor(n/a) * b가 된다.
다른 답과 시간 차이가 엄청 난다 아이고...
와... 진짜 머리 좋다...