This question is tragic. Joseph's mathematical solution has never been heard of it.
This is the case when I look up the Internet. The thought is like this, because every time you report a number, you will get rid of a person. If we do not consider the number, get people (people are different .) For example, as long as you have fixed the beginning, the only person must be the last one left behind, and the START will not change.
In fact, we play this game in real life as follows: remove a person, re-arrange the number, then remove a person, re-arrange the number, then remove a person, and then get the last person.
This is actually in line with our common sense, but it is troublesome for us to solve the problem, that is, how do we distinguish these people? Of course, we need to give each person a unique number, then the only problem we need to solve is how to get the number, instead of the number we re-compile each time?
There is a formula: F [I] = (F [I-1] + M) % I; it is a bit hard to understand, but it can still be understood if it is understood, in fact, when you do I must have removed the number of the M-1, it is actually you use F [I-1] To get the re-number plus our M is that is the starting to set the number.
But you can't think too much. If you think too much, you may be able to tear your mind apart. I have to understand it!
I don't quite understand the final result. I will continue to think about it after dinner and edit it later.
Paste the Code:
#include <stdio.h>#include <string.h>#include <iostream>#include <string>using namespace std;const int MAXN = 10000 + 5;int f[MAXN];int main(){int n, k, m;while (scanf("%d%d%d", &n, &k, &m) != EOF){if (n == 0 && k == 0 && m == 0){break;}if (n == 1){printf("1\n");continue;}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;if (ans <= 0){ans += n;}printf("%d\n", ans);}//system("pause");return 0;}