using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _3
{
/*class Shu
{
public void make(int[] b,int n,int s,int m)
{
int[] b2=new int[n];
for (int i = 0; i <= n; i++)
{
b2[i] = b[i];
if (((i+s) % m) == 0)
{
Console.WriteLine(b[i]);
n--;
for (int j = i; j < n; j++)
{
b2[j] = b[j + 1];
//Console.Write(b2[i]);
}
}
}
if (n==1) return;
make(b2, n, s, m);
}
}*/
public class Josephas
{
//总人数为n , 从第s人开始计数,以m为单位循环记数出列
public int [ ] Jose(int n, int s, int m)
{
int i, j, k = 0;
//count数组存储按出列顺序的数据,以当结果返回
int[] count = new int [ n+1];
//s数组存储初始数据
int[] sum = new int [ n+1];
//对数组sum赋初值,第一个人序号为0,第二人为1,依此下去
for (i = 0; i <=n; i++)
{
sum[i] = i;
}
//按出列次序依次存于数组count中
for (i = n; i >= 2; i--)
{
s = (s + m - 1) % i;
if (s == 0)
s = i;
count[k] = sum[s];
//Console.Write(count[k]);
k++;
for (j = s + 1; j <= i; j++)
sum[j - 1] = sum[j];
}
count[k]=sum[1];
//结果返回
return count;
}
}
class Program
{
static void Main(string[] args)
{
/*int n=0,s=0,m=0;
n = Convert.ToInt32(Console.ReadLine());
s = Convert.ToInt32(Console.ReadLine());
m = Convert.ToInt32(Console.ReadLine());
int[] x=new int[n];
Shu sh = new Shu();
for (int i = 0; i < n; i++) x[i] = i+1;
sh.make(x, n, s, m);
Console.ReadLine();*/
int n = 0, s = 0, m = 0;
Console.Write("请输入总人数n:");
n = Convert.ToInt32(Console.ReadLine());
Console.Write("请输入开始报数位置s:");
s = Convert.ToInt32(Console.ReadLine());
Console.Write("请输入第几个出列数m:");
m = Convert.ToInt32(Console.ReadLine());
int[] count=new int[n];
Josephas jp = new Josephas();
count=jp.Jose(n, s, m);
for (int i = 0; i <n; i++)
{
Console.Write(count[i]+" ");
}
Console.ReadLine();
}
}
}