http://tjuacm.chaosheng.top/problem.php?id=1251
#include <iostream> #include <cstdio> #include <cstring> #include <queue> using namespace std; int main(){ int t, n, k; cin >> t; for(int j = 1; j <= t; j++){ cin >> n >> k; queue<int> q; for(int i = 1; i <= n; i++){ q.push(i); } int tt = 1; while(q.size() > 1) { if(tt % k == 0){ q.pop(); }else{ int tmp = q.front(); q.pop(); q.push(tmp); } tt++; } printf("Case %d: %d\n", j, q.front()); } return 0; }