Cod sursa(job #2139099)

Utilizator theoioanaTheodoraD theoioana Data 22 februarie 2018 03:29:21
Problema Al k-lea termen Fibonacci Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.4 kb
#include<iostream>
#include<fstream>

using namespace std;

ifstream fin("kfib.in");
ofstream fout("kfib.out");

int main() {

	int cterm = 1, aterm = 1;

	int k; fin >> k;

	if (k == 1 || k == 2) {
		fout << 1;
	}
	else {
		k -= 2;
		int aux;
		while (k > 0) {
			aux = cterm;
			cterm = cterm + aterm;
			aterm = aux;
			k--;
		}
		fout << cterm % 666013;
	}


	return 0;
}