лови, код, работяга :
#include <iostream>
using namespace std;
int fibo(int n) {
if (n == 1 || n == 2)
return 1;
return fibo(n - 1) + fibo(n - 2);
}
signed main(){
int k, l = 1, r = 40;
cin >> k;
while(l <= r){
int m = (l + r)/2;
if(fibo(m) == k){
cout << m;
return 0;
else if(fibo(m) < k)
l = m + 1;
else
r = m - 1;
cout << -1;
лови, код, работяга :
#include <iostream>
using namespace std;
int fibo(int n) {
if (n == 1 || n == 2)
return 1;
return fibo(n - 1) + fibo(n - 2);
}
signed main(){
int k, l = 1, r = 40;
cin >> k;
while(l <= r){
int m = (l + r)/2;
if(fibo(m) == k){
cout << m;
return 0;
}
else if(fibo(m) < k)
l = m + 1;
else
r = m - 1;
}
cout << -1;
}