32 lines
579 B
C++
32 lines
579 B
C++
#include <iostream>
|
|
#include <array>
|
|
|
|
constexpr int MAX_N = 21;
|
|
|
|
// 编译期生成斐波那契数列
|
|
constexpr std::array<int, MAX_N> make_fib() {
|
|
std::array<int, MAX_N> fib{}; // 零初始化
|
|
fib[0] = 1;
|
|
fib[1] = 1;
|
|
for (int i = 2; i < MAX_N; ++i) {
|
|
fib[i] = fib[i - 1] + fib[i - 2];
|
|
}
|
|
return fib;
|
|
}
|
|
|
|
static constexpr auto fib = make_fib();
|
|
|
|
int x;
|
|
|
|
int main() {
|
|
std::ios::sync_with_stdio(false);
|
|
std::cin.tie(nullptr);
|
|
|
|
std::cin >> x;
|
|
while (std::cin >> x) {
|
|
std::cout << fib[x - 1] << std::endl;
|
|
}
|
|
|
|
return 0;
|
|
}
|