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. JQ库函数记忆要点

    1.核心(1.核心函数2.对象访问3.数据缓存4.队列控制4.插件机制5.多库共存) 2.属性(1.属性2.css类3.HTML代码/文本/值) 3.选择器(表单,表单对象属性,基本,内容,子元素,层 ...

  2. nginx+nginx-rtmp-module+ffmpeg搭建流媒体服务器[转]

    转 :http://redstarofsleep.iteye.com/blog/2123752 Nginx本身是一个非常出色的HTTP服务器,FFMPEG是非常好的音视频解决方案.这两个东西通过一个n ...

  3. Apache 配置参考

    1.什么是Apache ? Apache,是一种开放源码的HTTP服务器,可以在大多数操作系统中运行,由于其多平台和安全性所以被广泛使用,是目前最流行的Web服务器软件之一.Apache 起初由 Il ...

  4. spring和hibernate整合时无法自动建表

    在使用spring整合hibernate时候代码如下: <property name="dataSource" ref="dataSource" /> ...

  5. bootstrap按钮

    按钮 基类 -btn 样式 btn-default(默认) btn-link(链接) 大小 btn-*[lg,sm,xs] 状态 active disabled <!DOCTYPE HTML&g ...

  6. iOS 中 为UIView添加背景图片

    创建UIImage的方法有两种: UIImage *image = [UIImageimageNamed:@"image.jpg"];//这种不释放内存,要缓存 NSString ...

  7. 【转】关于Class.getResource和ClassLoader.getResource的路径问题

    Java中取资源时,经常用到Class.getResource和ClassLoader.getResource,这里来看看他们在取资源文件时候的路径问题. Class.getResource(Stri ...

  8. 用pywinauto进行win32应用程序的测试

    之前做win32应用测试时,用过很多大家耳熟成详的工具,接触pywinauto之前,对它的了解也不多,然而,随着对它了解的增多,发现它借助了python动态对象的能力,使得代码即便于书定,也便于阅读, ...

  9. 77 找出最大连续自然数个数[Longest Consecutive Sequence in an Unsorted Array]

    [本文链接] http://www.cnblogs.com/hellogiser/p/Longest-Consecutive-Sequence-in-an-Unsorted-Array.html [题 ...

  10. MongoDB 查询优化分析

    摘要: 在MySQL中,慢查询日志是经常作为我们优化查询的依据,那在MongoDB中是否有类似的功能呢?答案是肯定的,那就是开启Profiling功能.该工具在运行的实例上收集有关MongoDB的写操 ...