约瑟夫环数学公式

#include<stdio.h>
int main()
{
  int n,d;
  while(~scanf("%d %d",&n,&d))//输入总人数和去除数
  {
    long long w=0;
    for(int i=2;i<=n;i++)
    w=(w+d)%i;
    printf("%d %d %I64d\n",n,d,w+1);
  }
  return 0;
}

题目链接

http://acm.hdu.edu.cn/showproblem.php?pid=2925

猜你喜欢

转载自www.cnblogs.com/1998LJY/p/9318075.html