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. Python 学习笔记三

    笔记三:函数 笔记二已取消置顶链接地址:http://www.cnblogs.com/dzzy/p/5289186.html 函数的作用: 給代码段命名,就像变量給数字命名一样 可以接收参数,像arg ...

  2. U盘安装ubuntu server 14.04

    U盘安装ubuntu server 14.04 U盘安装ubuntu server 14.04 1.制作启动u盘 2.开始安装 1 将u盘插入主机,重启后从u盘启动 2 选择语言(随便挑,随便选),我 ...

  3. [转]Mysql海量数据存储和解决方案之一—分布式DB方案

    1)  分布式DB水平切分中用到的主要关键技术:分库,分表,M-S,集群,负载均衡 2) 需求分析:一个大型互联网应用每天几十亿的PV对DB造成了相当高的负载,对系统的稳定性的扩展性带来极大挑战. 3 ...

  4. MyEclipse 10 集成Maven

    第一步:安装Maven,作者安装目录是:D:\Java\apache-maven-3.2.5 第二步:配置本地仓库 maven将每次应用过的项目.文件.jar都会存储到maven的仓库中(默认仓库位置 ...

  5. 关于 strcpy 段错误

    int main(){ char * s = "hello,world" ; char *t = "happy"; strcpy(s,t) ; // error ...

  6. zookeeper部署及集群测试

    zookeeper部署及集群测试 环境 三台测试机 操作系统: centos7 ; hostname: c1 ; ip: 192.168.1.80 操作系统: centos7 ; hostname: ...

  7. (转)关于Certificate、Provisioning Profile、App ID的介绍及其之间的关系

    转自http://www.cnblogs.com/cywin888/p/3263027.html 刚接触iOS开发的人难免会对苹果的各种证书.配置文件等不甚了解,可能你按照网上的教程一步一步的成功申请 ...

  8. qq开放平台测试

    2015年3月10日 11:29:56 QQ API对一些链接的curl请求时, 有https, 所以需要安装openssl:  Linux上要安装openssl #yum -y install op ...

  9. 在Linux服务器上配置phpMyAdmin

    使用php和mysql开发网站的话,phpmyadmin是一个非常友好的mysql管理工具,并且免费开源,国内很多虚拟主机都自带这样的管理工具,配置很简单,接下来在linux服务器上配置phpmyad ...

  10. SQL触发器中若取到null值可能引发的问题

    declare @code varchar(20), @cs varchar(20),@zc varchar(20)set @cs='('+@cs+'*'+@zc+')'print '字符'+@csi ...