#include <array>
#include <cstdint>
#include <iostream>
#include <stdexcept>
#if 1 // Not in C++11 // make_index_sequence
template <std::size_t...> struct index_sequence {};
template <std::size_t N, std::size_t... Is>
struct make_index_sequence : make_index_sequence<N - 1, N - 1, Is...> {};
template <std::size_t... Is>
struct make_index_sequence<0u, Is...> : index_sequence<Is...> {};
#endif // make_index_sequence
namespace detail
{
template <std::size_t N>
struct Fibo :
std::integral_constant<size_t, Fibo<N - 1>::value + Fibo<N - 2>::value>
{
static_assert(Fibo<N - 1>::value + Fibo<N - 2>::value >= Fibo<N - 1>::value,
"overflow");
};
template <> struct Fibo<0u> : std::integral_constant<size_t, 0u> {};
template <> struct Fibo<1u> : std::integral_constant<size_t, 1u> {};
template <std::size_t ... Is>
constexpr std::size_t fibo(std::size_t n, index_sequence<Is...>)
{
return const_cast<const std::array<std::size_t, sizeof...(Is)>&&>(
std::array<std::size_t, sizeof...(Is)>{{Fibo<Is>::value...}})[n];
}
template <std::size_t N>
constexpr std::size_t fibo(std::size_t n)
{
return n < N ? fibo(n, make_index_sequence<N>()) : throw std::runtime_error("out of bound");
}
} // namespace detail
constexpr std::size_t fibo(std::size_t n)
{
// 48u is the highest
return detail::fibo<48u>(n);
}
int main()
{
std::cout << fibo(42) << std::endl;
std::size_t input;
std::cin >> input;
std::cout << fibo(input) << std::endl;
return 0;
}
I2luY2x1ZGUgPGFycmF5PgojaW5jbHVkZSA8Y3N0ZGludD4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RkZXhjZXB0PgoKI2lmIDEgLy8gTm90IGluIEMrKzExIC8vIG1ha2VfaW5kZXhfc2VxdWVuY2UKCnRlbXBsYXRlIDxzdGQ6OnNpemVfdC4uLj4gc3RydWN0IGluZGV4X3NlcXVlbmNlIHt9OwoKdGVtcGxhdGUgPHN0ZDo6c2l6ZV90IE4sIHN0ZDo6c2l6ZV90Li4uIElzPgpzdHJ1Y3QgbWFrZV9pbmRleF9zZXF1ZW5jZSA6IG1ha2Vf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