#include<stdio.h>
int fib(int n) {
if (n == 1 || n == 2) {
return 1;
}
return fib(n - 1) + fib(n - 2);
}
int isfib(int m)
{
int result=0;
for(int i=0;fib(i)<m;i++) {
if(fib(i+1)==m)
{
result=1;
break;
} else
result=0;
}
return result;
}
int LeftNum(int x) {
int cur;
int count=0;
cur=isfib(x);
if(cur==1) {
return count;
} else {
x++;
count++;
if(isfib(x)==1)
return count;
}
if(isfib(x)==0)
return 0;
}
int RightNum(int x) {
int cur;
int count=0;
cur=isfib(x);
if(cur==1) {
return count;
} else {
x++;
count--;
if(isfib(x)==1)
return count;
}
if(isfib(x)==0)
return 0;
}
int main() {
int x;
scanf("%d",&x);
int Right,Left;
Right=RightNum(x);
Left=LeftNum(x);
if(Right>=Left) {
printf("%d",Left);
} else{
printf("%d",Right);
}
return 0;
}
判断斐波那契
最新推荐文章于 2021-05-13 21:42:08 发布