• + 1 comment

    Yeah! You are right and the description is easy. I sloved this problem with the same way. The following is my AC code :)

    int main() {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT */   
        int t,n,c,m;
        cin>>t;
        while(t--){
            cin>>n>>c>>m;
            int answer=0;
            // Computer answer(the total of chocolates Bob eats)
            // answer consists of two parts: directly buy with money and exchange with wrapper
    
            int answer1 = n / c; // the number of buying with money
            answer += answer1;
    
            int answer2 = 0; // the number of exchanging with wrapper
    
            int wrapper = answer1 / m; // the number of first exchange with wrapper
            int remain = answer1 % m; // the number of first remain wrapper
            answer2 += wrapper;
    
            int available = wrapper + remain;
            while (available / m != 0) {
                wrapper = available / m;
                remain = available % m;
    
                answer2 += wrapper;
                available = wrapper + remain;
            }
    
            answer += answer2;
    
            cout<<answer<<endl;
        }
        return 0;
    }