And Then There Was One
Sample Input
8 5 3 100 9999 98 10000 10000 10000 0 0 0
Sample Output
1 93 2019
//设f[i]为(原约瑟夫问题)第i次要删除的标号 #include<cstdio> using namespace std; const int N=1e4+5; int n,m,k,f[N]; int main(){ while(scanf("%d%d%d",&n,&k,&m)==3&&n){ //f[1]=0; //for(int i=2;i<=n;i++) f[i]=(f[i-1]+k)%i; //int ans=(m-k+f[n]+1)%n; int s=0; for(int i=2;i<=n;i++) s=(s+k)%i; int ans=(m-k+s+1)%n;//这3句话来源于上面 if(ans<=0) ans+=n; printf("%d ",ans); } return 0; }