Pagini recente » Cod sursa (job #1928863) | Cod sursa (job #1051783) | Rating vlad beraru alexandru (vladberaru) | Cod sursa (job #3281217) | Cod sursa (job #2894658)
//
// Purposefully built to learn C++ template metaprogramming
// Inspired by
// https://en.wikipedia.org/wiki/Template_metaprogramming#Static_Table_Generation
//
#include <array>
#include <cstdlib>
#include <fstream>
#include <iostream>
using namespace std;
constexpr int mod = 666013;
constexpr int MAX_SIZE = 131071;
constexpr array<int, 2 *mod + 2> fibonacci = [] {
array<int, 2 *mod + 2> result = {};
int previous = 0;
int current = 1;
int next = 1;
for (int i = 0; i < MAX_SIZE; i++) {
result[i] = current;
next = (previous + current) % mod;
previous = current;
current = next;
}
return result;
}();
int main() {
ifstream f("kfib.in");
ofstream g("kfib.out");
int n;
f >> n;
cout << (n - 1) % (2 * mod + 2);
g << fibonacci[(n - 1) % (2 * mod + 2)];
return 0;
}