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. 用 ROS 做内网DNS服务器

    转载:http://iliuyong.iteye.com/blog/1035692 用 ROS 做内网DNS服务器方法:1.ROS 设置IP ->DNS 选择"static" ...

  2. win8_64下安装paramiko

    win8_64下安装paramiko C:\Python35\Scripts>easy_install paramiko 提示 C:\Python35\Scripts>python Pyt ...

  3. PyQt4关闭最大化最小化取消双击最大化

    self.setWindowFlags(Qt.Window | Qt.WindowTitleHint | Qt.WindowCloseButtonHint | Qt.CustomizeWindowHi ...

  4. 3. Android程序生成步骤

      主要流程如下图所示:       所需要的工具列表 名称 功能介绍 在操作系统中的路径 aapt Android资源打包工具 ${ANDROID_SDK_HOME}/platform-tools/ ...

  5. json方式封装接口通信

    编写response类: <?php class response{ /** * 按json方式输出通信数据 * @param integer $code 状态码 * @param string ...

  6. eos超时 锁表问题 网友办法

    select * from v$locked_object; SELECT sid, serial#, username, osuser FROM v$session where sid = 45; ...

  7. chrome调试命令模式

    哈哈哈

  8. [转]C++中四种类型转换符的总结

    C++中四种类型转换符的总结 一.reinterpret_cast用法:reinpreter_cast<type-id> (expression)    reinterpret_cast操 ...

  9. git命令使用

    2015-07-15 11:59:11 git pull : 相当于 SVN up git status : 相当于 SVN st git add a.txt: 新添加文件 或者 将文件修改保存到索引 ...

  10. Androd核心基础01

    Androd核心基础01包含的主要内容如下 Android版本简介 Android体系结构 JVM和DVM的区别 常见adb命令操作 Android工程目录结构 点击事件的四种形式 电话拨号器Demo ...