题目传送:UVA - 10183
思路:高精度就可以了,因为10^100以内的斐波那契数不多,根据公式来看,估计就500多,开个1000的数组足够啦,实现的话是用的java,注意这里的斐波那契是从1开始的,我一开始是从0开始的,wa了一下
AC代码:
import java.util.Scanner; import java.math.BigInteger; public class Main { public static void main(String args[]) { Scanner cin = new Scanner(System.in); BigInteger a, b; BigInteger[] fibo = new BigInteger[1005]; fibo[0] = new BigInteger("1"); fibo[1] = new BigInteger("2"); for(int i = 2; i < 1005; i ++) { fibo[i] = fibo[i - 2].add(fibo[i - 1]); } while(true) { a = cin.nextBigInteger(); b = cin.nextBigInteger(); if(a.compareTo(BigInteger.ZERO) == 0 && b.compareTo(BigInteger.ZERO) == 0) { break; } int ans = 0; for(int i = 0; i < 1005; i ++) { if(fibo[i].compareTo(a) != -1 && fibo[i].compareTo(b) != 1) { ans ++; } } System.out.println(ans); } } }
UVA - 10183 - How Many Fibs? (斐波那契 + 高精度)
原文地址:http://blog.csdn.net/u014355480/article/details/45395079