#include <iostream>
int f(int n, int m){
register int new_index = 1;
register int old_index = 1;
for (int k = 2;k <= n;k++) {
old_index = (new_index + m - 1) % k + 1;
new_index = old_index;
}
return old_index;
}
int f1(int n, int m) {
return n == 1 ? n : (f(n - 1, m) + m - 1) % n + 1;
}
int main() {
for (int i = 0;i < 100000000;i++) {
f(6, 3); // 2.013s
// f1(6, 3); // 2.51s
}
return 0;
}