摆在这个位置肯定是有通用的简易构造方法的。
想一想怎么样才能快速把数值升到差不多和 一个量级,很显然最快的做法就是先令 ,然后交替做 和 。
在这个过程中 和 的变化是什么?观察得到这个是斐波那契数列。
那事情就简单了,如果 恰好是一个斐波那契数,那么令 或 之中的一个为 ,然后交替这样做就可以凑出 了。
进一步扩展到一般的 ,它肯定可以被分解成若干个斐波那契数之和。一边交替做,一边加上新的斐波那契数起点即可。
constexpr int M = 88;
i64 fib[M];
i64 n;
std::vector<int> Div;
int tag[M][2];
int main() {
#ifdef HeratinoNelofus
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cin >> n;
fib[0] = 1, fib[1] = 1;
for (int i = 2; i < M; i++)
fib[i] = fib[i - 1] + fib[i - 2];
for (int i = M - 1; i >= 1; i--) {
if (n >= fib[i])
n -= fib[i], Div.push_back(i);
}
int lst = (Div[0] - 1) / 2 + 1;
for (const int &x : Div) {
int p = (x - 1) / 2 + 1;
if (x & 1) {
tag[lst + 1 - p][1] = 1;
} else {
tag[lst + 1 - p][0] = 1;
}
}
std::vector<int> ope;
for (int i = 1; i <= lst; i++) {
ope.push_back(3);
if (tag[i][0])
ope.push_back(1);
ope.push_back(4);
if (tag[i][1])
ope.push_back(2);
}
ope.push_back(3);
std::cout << ope.size() << '\n';
for (const int &x : ope)
std::cout << x << '\n';
return 0;
}