Cod sursa(job #1991371)
Utilizator | Data | 16 iunie 2017 15:05:54 | |
---|---|---|---|
Problema | Al k-lea termen Fibonacci | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.45 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("kfib.in");
ofstream out("kfib.out");
int v[1400005];
int main()
{
v[1] = 1;
v[2] = 1;
int n = 2, k;
in >> k;
bool ok = 0;
while(ok == 0)
{
v[++n] = (v[n - 1] + v[n - 2]) % 666013;
if(v[n] == 1 && v[n - 1] == 1)
{
ok = 1;
n -= 2;
}
}
out << v[k % n];
return 0;
}