记录编号 598199 评测结果 AAAAA
题目名称 约瑟夫问题 最终得分 100
用户昵称 Gravatarchenbp 是否通过 通过
代码语言 C++ 运行时间 0.017 s
提交时间 2025-01-22 17:15:25 内存使用 3.28 MiB
显示代码纯文本
#include <iostream>
#include <cstdio>
using namespace std;
bool a[105];
int main(){
    freopen("ysf.in","r",stdin);
    freopen("ysf.out","w",stdout);
    int n,k;
    cin>>n>>k;
    int now=0;
    for(int i=1;i<=n;i++){
        int tot=0;
        int s=k%(n-i+1);
        if(s==0) s=n-i+1;
        while(tot<s){
            now++;
            if(now>n) now=1;
            if(!a[now]) tot++;
        }
        a[now]=1;
        cout<<now<<endl;
    }
    return 0;
}