Cod sursa(job #651473)

Utilizator geniucosOncescu Costin geniucos Data 20 decembrie 2011 16:16:22
Problema Al k-lea termen Fibonacci Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.51 kb
#include<stdio.h>
using namespace std;
long long x,y,poz;
long long fib(int n)
{
	if(n==1||n==2) return 1;
	else
	if(n==3) return 2;
	else
	if(n==4) return 3;
	else
	{
		if(n%2==0)
		{
			x=fib(n/2+1);
			y=fib(n/2-1);
			return (x*x-y*y)%666013;
		}
		else
		{
			x=fib(n/2);
			y=fib(n/2+1);
			return ((x*x)%666013+(y*y)%666013)%666013;
		}
	}
}
int main()
{
freopen("kfib.in","r",stdin);
freopen("kfib.out","w",stdout);
scanf("%d",&poz);
//poz--;
printf("%d\n",fib(poz));
return 0;
}