让球第n个斐波那契数,Java大数,用Java写大数就是简单,虽然效率可能比C++的慢点。
类似题目
HDU-1316题解
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String [] args){
Scanner in = new Scanner(System.in);
BigInteger a,b;
BigInteger ZERO = BigInteger.ZERO;
while(in.hasNext())
{
int n = in.nextInt();
System.out.println(Fib(n));
}
}
//第一次写函数啊
public static BigInteger Fib(int n)
{
int sum = 0;
BigInteger f = new BigInteger("1");
BigInteger s = new BigInteger("1");
BigInteger tmp;
while(++sum < n)
{
tmp = f;
f = s;
s = s.add(tmp);
}
return f;
}
}