How many Fibs?

Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^

题目描述

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].

输入

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<=10100. The numbers aand b are given with no superfluous leading zeros.

输出

 

示例输入

10 100
1234567890 9876543210
0 0

示例输出

5
4

提示

 

来源

2000/2001 University of Ulm Local Contest

示例程序

题目大意:

输入两个整数,求这两个整数之间的斐波纳契数的个数,即求[a,b]之间斐波那契数的个数,输入以0 0结束(a,b两个数可以到10^100次幂)

代码:
很多大数的问题用java做的话一定比c语言或者c++语言做起来简单~
 import java.io.*;
import java.math.*;
import java.util.*;
public class Main
{
public static void main(String args[])
{
Scanner scn=new Scanner(System.in);
while(true)
{
BigInteger a=scn.nextBigInteger();
BigInteger b=scn.nextBigInteger();
if(a.equals(new BigInteger("0"))&&b.equals(new BigInteger("0")))
{
break;
}
BigInteger f[]=new BigInteger[20000];
f[1]=new BigInteger("1");
f[2]=new BigInteger("2");
int i;
for(i=3;i<=600;i++)
{
int temp=i;
f[i]=f[temp-1].add(f[temp-2]);
}
int count=0;
for(i=1;i<=600;i++)
{
if(f[i].compareTo(a)==0)
{
count=1;
}
else if(f[i].compareTo(a)>0&&f[i].compareTo(b)<=0)
{
count++;
}
else if(f[i].compareTo(b)>0)
{
break;
}
}
System.out.println(count);
}
}
}

How many Fibs?【sudt 2321】【大数的加法及其比较】的更多相关文章

  1. 剑指offer编程题Java实现——面试题12相关题大数的加法、减法、乘法问题的实现

    用字符串或者数组表示大数是一种很简单有效的表示方式.在打印1到最大的n为数的问题上采用的是使用数组表示大数的方式.在相关题实现任意两个整数的加法.减法.乘法的实现中,采用字符串对大数进行表示,不过在具 ...

  2. 抓起根本(二)(hdu 4554 叛逆的小明 hdu 1002 A + B Problem II,数字的转化(反转),大数的加法......)

    数字的反转: 就是将数字倒着存下来而已.(*^__^*) 嘻嘻…… 大致思路:将数字一位一位取出来,存在一个数组里面,然后再将其变成数字,输出. 详见代码. while (a) //将每位数字取出来, ...

  3. Integer Inquiry【大数的加法举例】

    Integer Inquiry Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 27730   Accepted: 10764 ...

  4. 大数的加法函数--c语言

    浏览网站http://paste.ubuntu.com/23687758/ #include<stdio.h> #include<stdlib.h> #include<s ...

  5. How many Fibs?(poj 2413)大数斐波那契

    http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=259#problem/C Description Recall the defi ...

  6. 大数的加法运算,杭电oj-1002

    原题地址:http://acm.hdu.edu.cn/showproblem.php?pid=1002   [Problem Description] I have a very simple pro ...

  7. hdu 1002 A + B Problem II【大数加法】

    题目链接>>>>>> 题目大意:手动模拟大数加法,从而进行两个大数的加法运算 #include <stdio.h> #include <strin ...

  8. K:大数加法

    相关介绍:  在java中,整数是有最大上限的.所谓大数是指超过整数最大上限的数,例如18 452 543 389 943 209 789 324 233和8 123 534 323 432 323 ...

  9. hdu1865 1sting (递归+大数加法)

    1sting Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Subm ...

随机推荐

  1. hdu1455 dfs+剪枝

    Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  2. 线段树区间更新&&求和poj3486

    给出了一个序列,你需要处理如下两种询问. ≤ c ≤ ). "Q a b" 询问[a, b]区间中所有值的和. Input 第一行包含两个整数N, Q. ≤ N,Q ≤ . 第二行 ...

  3. Linux Ruijie登录命令

    cd rjsupplicant chmod +x rjsupplicant.sh sudo ./rjsupplicant.sh -u 1550590×××× -p ××××× -d 1

  4. zipimport.ZipImportError: can't decompress data; zlib not available 解决办法

    第一步,下载python-pip的tar包 # wget https://pypi.python.org/packages/source/p/pip/pip-1.3.1.tar.gz --no-che ...

  5. django 1.7+ default_permissions

    由于做Caption要做权限设计.在核心类的设计的时候需要做好权限的基础设计.django 1.7+以后 django.db.modes新增特性 default_permissions,官方文档语焉不 ...

  6. 【实例】html5-canvas中实现背景图片的移动

    本例来自于<HTML5 Canvas核心技术 图形.动画与游戏开发> 在线演示 (图有点多,请多刷新几次) 本例还有一点代码不理解,我用注释和问号标注出来了,有大神看到求解答,谢谢 本例子 ...

  7. 不懂点CAP理论,你好意思说你是做分布式的吗?

  8. 《转载》化繁为简 如何向老婆解释MapReduce?

    本文转载自http://server.zol.com.cn/329/3295529.html 昨天,我在Xebia印度办公室发表了一个关于MapReduce的演说.演说进行得很顺利,听众们都能够理解M ...

  9. 《转》---google面经

    我面的职位是Softwre Engineer, Tools and Infrastracture, 所以开发和测试的问题都会问到 Phone interview 1:白人小哥.给一个Interval的 ...

  10. jenkins集成ansible注意事项Failed to connect to the host via ssh.

    在集成jenkins和ansible实现自动化部署时,root用户下执行ansible命令时可以正常运行.由于是通过jenkins用户去执行ansible命令,而jenkins用户却报如下异常: XX ...