#include<iostream> #include<string> #include<algorithm> #include<cmath> #include<iomanip> using namespace std; //公式:f(N,M)=(f(N−1,M)+M)%N (此公式返回的是从0开始计算的数组下标) //公式中N为总人数,每报到M时去掉那个人 int func(int n, int m) { if (n == 1) return 0; else { int res = 0; for (int i = 2; i <= n; i++) res = (res + 3) % i; return res; } } int main() { int n; while (cin >> n && n != 0) cout << func(n, 3) + 1 << endl; return 0; } |
Double click to view unformatted code.