约瑟夫环

#include <iostream>
using namespace std;

int main()
{
    int n, m;
    while(cin>>n>>m) {
        int s = 0;
        for(int i=2;i<=n;i++) {
            s = (s+m)%i;
        }
        cout<<"The Winner is "<<s+1<<endl;
    }
}

posted on 2013-09-30 20:35  Knuth_档案  阅读(168)  评论(0编辑  收藏  举报

导航