转圈报数

#include <iostream>
#include <vector>
#include <stack>
#include <set>
#include <string>
#include <algorithm>
using namespace std;
int main(void) {	
	int m, n;
	while (cin>>m>>n) {
		vector<int> ans(m);
		for (int i = 1; i <= m;i++) {
			ans[i - 1] = i;
		}
		int i = 1;
		while (ans.size() > 1) {
			i = (i+n-1) % ans.size();
			cout << ans[i];
			ans.erase(ans.begin() + i);
		}
		cout << endl<<ans[0] << endl;
	}
	return 0;
}
posted @ 2021-11-18 20:27  Zupernova  阅读(14)  评论(0编辑  收藏  举报