An iterative 'simulation' problem:
#include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> using namespace std; int main() { int t, n, c, m; cin >> t; while (t--) { cin >> n >> c >> m; int answer = 0; // Computer answer answer = n / c; int wrapper = answer; while (wrapper >= m) { wrapper -= m; wrapper++; answer++; } cout << answer << endl; } return 0; }