//f(1) = 1, f(2) = 1, f(n > 2) = f(n - 1) + f(n - 2)
import java.io.*;
import java.util.*;
import java.math.*;public class Main {
/**
* @xqq
*/
public BigInteger an(int n) {
BigInteger c;
BigInteger a = BigInteger.valueOf(1);
BigInteger b = BigInteger.valueOf(1);for(int i = 1; i < n; i++) {
c = a.add(b);
a = b;
b = c;
}
return a;
}
public static void main(String[] args) throws Exception {
// 定义并打开输入文件
Scanner cin = new Scanner(System.in);Main e = new Main();
int n;while(cin.hasNext()) {
n = cin.nextInt();
System.out.println(e.an(n));
}cin.close(); //关闭输入文件
}
}
zoj Fibonacci Numbers ( java , 简单 ,大数),码迷,mamicode.com
时间: 2024-12-23 15:37:12