// Вычисление за O(1) !!!!
// На самом деле это просто "магия шаблонов" и constexpr
// Задача решается на этапе компиляции компилятором
// В рантайме просто выводится результат
#include <iostream>
#include <array>
#include <utility>
using namespace std;
template<size_t N>
struct helper
{
static constexpr size_t other = 2 * (helper<N-1>::other + helper<N-1>::end_2);
static constexpr size_t end_2 = helper<N-1>::other / 2 + helper<N-1>::end_2;
};
template<>
struct helper<1>
{
static constexpr size_t other = 2;
static constexpr size_t end_2 = 1;
};
template <size_t N>
struct task126
{
static constexpr size_t Value = helper<N>::other + helper<N>::end_2;
};
void print_values(index_sequence<>)
{
}
template <size_t H, size_t ...Rest> constexpr void print_values(index_sequence<H, Rest...>)
{
cout << H << endl;
print_values(index_sequence<Rest...>());
}
template <size_t ...N> constexpr void solve(index_sequence<N...>)
{
print_values(index_sequence<task126<N+1>::Value...>());
}
int main() {
solve(make_index_sequence<30>());
return 0;
}
Ly8g0JLRi9GH0LjRgdC70LXQvdC40LUg0LfQsCBPKDEpICEhISEKLy8g0J3QsCDRgdCw0LzQvtC8INC00LXQu9C1INGN0YLQviDQv9GA0L7RgdGC0L4gItC80LDQs9C40Y8g0YjQsNCx0LvQvtC90L7QsiIg0LggY29uc3RleHByCi8vINCX0LDQtNCw0YfQsCDRgNC10YjQsNC10YLRgdGPINC90LAg0Y3RgtCw0L/QtSDQutC+0LzQv9C40LvRj9GG0LjQuCDQutC+0LzQv9C40LvRj9GC0L7RgNC+0LwKLy8g0JIg0YDQsNC90YLQsNC50LzQtSDQv9GA0L7RgdGC0L4g0LLRi9Cy0L7QtNC40YLRgdGPINGA0LXQt9GD0LvRjNGC0LDRggoKI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YXJyYXk+CiNpbmNsdWRlIDx1dGlsaXR5PgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnRlbXBsYXRlPHNpemVfdCBOPgpzdHJ1Y3QgaGVscGVyCnsKICAgIHN0YXRpYyBjb25zdGV4cHIgc2l6ZV90IG90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