C++约瑟夫环
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #define sc(x) scanf("%d",&x) 6 #define pf(x) printf("%d\n",x) 7 #define CL(x,y) memset(x,y,sizeof(x)) 8 using namespace std; 9 int N; 10 int fun(int m); 11 int main() 12 { 13 sc(N); 14 fun(3); 15 return 0; 16 } 17 int fun(int m) 18 { 19 int i, r = 0; 20 for (i = 2; i <= N; i++) 21 { 22 r = (r + m) % i; 23 // cout << r << " " << i << endl; 24 } 25 cout << r+1 << endl; 26 return r+1; 27 }
数学思想:
http://blog.csdn.net/fzydao/article/details/7041541