【大数问题】 HDOJ 1316 How Many Fibs?

java~~

import java.util.Scanner;
import java.math.BigInteger;
import java.math.BigDecimal;

public class Main
{
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		BigInteger f[] = new BigInteger[1005];
		f[1] = BigInteger.valueOf(1);
		f[2] = BigInteger.valueOf(2);
		for(int i = 3; i < 1005; i++) {
			f[i] = BigInteger.ZERO;
			f[i] = f[i].add(f[i-1]);
			f[i] = f[i].add(f[i-2]);
		}
		BigInteger a, b, c;
		c = BigInteger.ZERO;
		while(scanner.hasNext()) {
			int ans = 0;
			a = scanner.nextBigInteger();
			b = scanner.nextBigInteger();
			if(a.compareTo(c) == 0 && b.compareTo(c) == 0) break;
			for(int i = 1; i <= 1000; i++)
				if(f[i].compareTo(a) >= 0 && f[i].compareTo(b) <= 0) ans++;
			System.out.println(ans);
		}
	}
}


你可能感兴趣的:(HDU)