斐波那契数列 · 通项公式

斐波那契数列

http://www.nowcoder.com/questionTerminal/c245af6cfdce49ceb5435f649ee14f89

通项公式:

import java.util.*;
public class Main {
    public static void main(String[] args) throws Exception{
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        double a = Math.sqrt(5.0);
        double temp1 = (1.0 + a)/2.0;
        double temp2 = (1.0 - a)/2.0;
        int r = (int)(1.0/a*(Math.pow(temp1, n) - Math.pow(temp2, n)));
        System.out.println(r);
    }
}
全部评论

相关推荐

09-12 14:05
一表renzha:招黑奴呢,我实习都6k,正式没1w我就不做程序员了
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务