package Fibonacci;
import java.util.Scanner;
import java.util.function.ObjLongConsumer;
public class Demo {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("输入一个数:");
Scanner scanner = new Scanner(System.in) ;
long n = scanner.nextLong();
long num = scanner.nextLong();
/* System.out.println("数所对应的Fibonacci的值:" + fib(n));
System.out.println("非递归-index所对应的Fibonacci的值:" + fibIndex(n));
*/
System.out.println("反向求index:");
fibReturn(n, num);
}
public static void fibReturn(long n ,long num) {
long f0 = 0;
long f1=1;
long f2= 1 ;
if(num == 0 )
System.out.println("0");
if(num == 1 || num ==2)
System.out.println("1");
for(int i= 3 ; i <=n ; i++) {
f0 = f1 ;
f1 = f2 ;
f2 = f0 + f1 ;
if(f2 ==num) {
System.out.println("此数所对应的索引值" + i);
}
}
}
}