约瑟夫环
n个人, 从1到n开始编号,每次数到m,就把那个人去掉。
问最后的那个人是谁
#pragma warning(disable:4996)
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<map>
#include<set>
#include<cmath>
#include<ctime>
#include<vector>
#include<queue>
#include<cstring>
#include<string>
#include<bitset>
#define SITE set<node>::iterator
using namespace std;
typedef long long ll;
const int inf = 1e8 + 10;
const ll mod = 1e9 + 7;
const int maxn = 1e7;
int ysf(int n, int val, int sum) {
if (n == 1)return (sum + val - 1) % sum;
else return (ysf(n - 1, val, sum - 1) + val) % sum;
}
int main()
{
int n, m;
cin >> n >> m;
cout << ysf(n, m, n) +1;
return 0;
}