読者です 読者をやめる 読者になる 読者になる

AOJ 0085 Joseph's Potato

Programming Algorithm AOJ

404 Not Found

#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
	int n, m;
	while(scanf("%d %d\n", &n, &m), n && m){
		vector<int> v;
		for(int i = 1; i <= n; i++) v.push_back(i); 
		vector<int>::iterator it = v.begin();
		while(1 < v.size()){
			for(int i = 1; it = it == v.end() ? v.begin() : it, i < m; i++)
				it++;
			it = v.erase(it);
		}
		printf("%d\n", v[0]);
	}
	return 0;
}