Cod sursa(job #2153236)
Utilizator | Data | 6 martie 2018 01:34:07 | |
---|---|---|---|
Problema | Al k-lea termen Fibonacci | Scor | 20 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.44 kb |
//#include <iostream>
#include <fstream>
#define M 666013
using namespace std;
ifstream f("kfib.in");
ofstream cout("kfib.out");
int k, k1=0, k2=1, k3;
int main()
{
int i;
f>>k;
if (k==0) cout<<k1;
else
if (k==1) cout<<k2;
else
{
for (i=2; i<=k; i++)
{
k3=(k1+k2)%M;
k1=k2;
k2=k3;
}
cout<<k3;
}
return 0;
}