#include <iostream>using namespacestd;intMain () {intA= -, b=3, winner=0;//Total number A, number to B in multiples of left, last man winner for(intI=2; i<=a;i++) Winner= (winner+b)%i; cout<<"Winner:"<<winner+1<<Endl;}
We consider the following process
1 2 3 4 5 6 ..... K-1 k k+1 ... n-1 n
The first number for the K-brother hangs, and then the rest of the n-1 individuals, from the k+1 continue.
K+1 k+1 .... n-1 N 1 2 3 4 5 6,
The sequence numbers are all minus k, resulting in the following sequences:
1 2 3 4 5 6 ..... N-1
That is n-1 personal situation.
Assuming that the last remaining person, in the sequence of the first (n-1) person is f (n-1), then he is in the N-man sequence, numbered (K+f (n-1))%n, and has our recursive formula:
F (n) = (k+f (n-1))%n;
F (1) = 1;
http://blog.csdn.net/ice110956/article/details/12906065
"Algorithm" Joseph Ring C + + source code