zoj1962题,求大神指导为什么wrong answer,vc已通过
How Many Fibs?--------------------------------------------------------------------------------
Time limit: 1 Seconds Memory limit: 32768K
Total Submit: 56 Accepted Submit: 37
--------------------------------------------------------------------------------
Recall the definition of the Fibonacci numbers:
f1 := 1
f2 := 2
fn := fn-1 + fn-2 (n >= 3)
Given two numbers a and b, calculate how many Fibonacci numbers are in the range [a, b].
Input
The input contains several test cases. Each test case consists of two non-negative integer numbers a and b. Input is terminated by a = b = 0. Otherwise, a <= b <= 10^100. The numbers a and b are given with no superfluous leading zeros.
Output
For each test case output on a single line the number of Fibonacci numbers fi with a <= fi <= b.
Sample Input
10 100
1234567890 9876543210
0 0
Sample Output
5
4
代码
#include <stdio.h>
#include <math.h>
int main()
{
double a,b,n,sum;
int i,j;
scanf("%lf%lf",&a,&b);
while(a!=0||b!=0)
{
sum=0;
j=0;
for(i=1;sum<=b;i++)
{
sum=((5+3*sqrt(5))/10)*pow(((1+sqrt(5)))/2,(double)(i-1))+((5-3*sqrt(5))/10)*pow(((1-sqrt(5)))/2,(double)(i-1));
if(sum>=a)
j++;
}
printf("%d\n",j-1);
scanf("%lf%lf",&a,&b);
}
return 0;
}
[ 本帖最后由 ren1375342 于 2012-12-4 14:21 编辑 ]