提交时间:2025-03-26 13:27:11

运行 ID: 63285

#include<bits/stdc++.h> using namespace std; int n = -1,m = -1; int f(int n,int m){ bool isCount[n+1] = {}; int takeSize =0; int index = 1; int cnt = 1; while(1){ if(isCount[index] == true){ index++; if(index == n+1)index =1; continue; } if(cnt == m){ isCount[index] = true; cnt = 1; takeSize++; if(takeSize == n-1)break; }else{ cnt++; } index++; if(index == n+1)index =1; } /* 1 2 3 4 5 6 1 3 4 5 6 1 3 5 6 1 3 5 1 5 5 */ int ans = -1; for(int i = 1;i<=n;i++)if(isCount[i] == false)return i; return ans; } int main(){ while(1){ cin>>n>>m; if(n == 0 && m == 0)break; cout<<f(n,m)<<endl; } return 0; }