Who solve this problem on C? Please give hint, why wrong 9?
Posted by
Lifanov 12 Apr 2005 13:31
#include <stdio.h>
#include <math.h>
int i,j,Fi,Fj,n;
int main(){
//freopen("in.txt","r",stdin);
scanf("%d%d%d%d%d",&i,&Fi,&j,&Fj,&n);
int t,k;
if(i>j){
t=i;
i=j;
j=t;
t=Fi;
Fi=Fj;
Fj=t;
}
// i < j
j-=i;
n-=i;
i=0;
// 0 j n
double f1=0.0,f2=1.0,f,tempf;
f=f1+f2;
for( k=1;k<j;k++){
f=f1+f2;
f1=f2;
f2=f;
}
//printf("%.0lf\n",f);
double F0=Fi;
double F1=floor((Fj-f1*F0)/f);
//printf("%.0lf\n",F1);
f1=F0;
f2 =F1;// modf(F1,&f2);
if(n>0){
for(k=1;k<n;k++){
f=f1+f2;
f1=f2;
f2=f;
}
f=f2;
}
else{
for(k=-1;k>n;k--){
f=f2-f1;
f2=f1;
f1=f;
}
f=f2;
}
printf("%.0lf",f);
return 0;
}
Edited by author 12.04.2005 13:48