#include <iostream>
#include <list>
using namespace std;
list<int> l;
int n;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) l.push_back(i);
int cur = 1;
auto it = l.begin();
while (l.size() > 1) {
++cur;
++it;
// 每次在自增迭代器时判断一下是否到末尾
if (it == l.end()) {
it = l.begin();
}
if (cur % 3 == 0) {
// printf("%d ", *it);
it = l.erase(it);
++cur;
if (it == l.end()) {
it = l.begin();
}
}
}
printf("%d\n", l.front());
return 0;
}
直接用STL
的list模拟就好