试题F:Fibonacci数列与黄金分割
import java.util.Scanner;
public class Main {
public static long f(int n){
if(n == 1 || n == 2){
return 1 ;
}else{
long [] res = new long [n+1] ;
res[1] = 1 ;
res[2] = 1 ;
for(int i=3; i<=n; i++){
res[i] = res[i-1] + res[i-2] ;
}
return res[n] ;
}
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in) ;
int n = input.nextInt();
if(n <= 19)
System.out.printf("%.8f", 1.0 * f(n)/f(n+1));
else{
System.out.println("0.61803399");
}
}
}