Cod sursa(job #1690573)

Utilizator valentin50517Vozian Valentin valentin50517 Data 15 aprilie 2016 11:56:26
Problema Al k-lea termen Fibonacci Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.36 kb
#include <fstream>
#include <map>
typedef long long ll;
#define mod 666013
using namespace std;
ifstream fin("kfib.in");
ofstream fout("kfib.out");
int K;
map<ll,ll> M;
ll f(ll k){
	if(M[k] != 0) return M[k];
	else return M[k] = (f((k+1)/2)*f(k/2) + f((k-1)/2)*f((k-2)/2))%mod;
}
int main(){
	fin >> K;
	M[0] = M[1] = 1;
	fout << f(K-1);
	
	return 0;
}