Mai intai trebuie sa te autentifici.
Cod sursa(job #935089)
Utilizator | Data | 1 aprilie 2013 15:38:40 | |
---|---|---|---|
Problema | Al k-lea termen Fibonacci | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.5 kb |
#include <iostream>
#include <fstream>
using namespace std;
int fib(int k)
{
if (k <= 0)
{
return 0;
}
if (k == 1)
{
return 1;
}
int a = 0;
int b = 1;
for (int i = 2; i <= k; ++i)
{
int t = (a + b) % 666013;
a = b;
b = t;
}
return b;
}
int main(int argc, char* argv[])
{
fstream in("kfib.in");
int k;
in >> k;
in.close();
int f = fib(k);
fstream out("kfib.out", ios::out);
out << f;
out << flush;
out.flush();
out.close();
return 0;
}