Pagini recente » Cod sursa (job #555951) | Cod sursa (job #170424) | Cod sursa (job #1473178) | Cod sursa (job #2984239) | Cod sursa (job #2894597)
//
// Haja Florin-Gabriel
// Purposefully built to learn C++ template metaprogramming
//
#include <array>
#include <cstdlib>
#include <fstream>
using namespace std;
constexpr int mod = 6013;
constexpr int MaxSize = 200;
template <int Index = 0, int Previous = 0, int Current = 1, int... D>
struct Helper
: Helper<Index + 1, Current, (Previous + Current) % mod, D..., Current> {};
template <int Previous, int Current, int... D>
struct Helper<MaxSize, Previous, Current, D...> {
static constexpr array<int, MaxSize> table = {D...};
};
constexpr array<int, MaxSize> fibonacci = Helper<>::table;
int main() {
ifstream f("kfib.in");
ofstream g("kfib.out");
int n;
f >> n;
g << fibonacci[n % (2 * mod + 2)];
return 0;
}