How Many Fibs?
How Many Fibs?
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5158 Accepted Submission(s):
2007
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].
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.
of Fibonacci numbers fi with a <= fi <= b.
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define len 10
int _cmp(char *a,char *b)
{
int i=,j,count=;
if(strlen(a)<strlen(b))
return ;
else if(strlen(a)>strlen(b))
return -;
else
{
char x[];
int j=,len1=strlen(a);
for(i=len1-;i>=;i--) /*倒置,全部都是高位在右,从右往左比较*/
x[j++]=a[i];
x[j]='\0';
i=len1-;
while(i>=)
{
if(b[i]>x[i])
return ;
else if(b[i]==x[i])
i--;
else
{
return -;
}
}
return ;
}
}
char f[][];
int main()
{
memset(f,'',sizeof(f));
int c,i,j,count,n;
char a[],b[];
f[][]='';
f[][]='';
for(i=;i<;i++)
{
c=;
for(j=;j<;j++)
{
f[i][j]=(f[i-][j]+f[i-][j]+c-*'')%len+'';
c=(f[i-][j]+f[i-][j]+c-*'')/len;
}
}
for(i=;i<;i++) /*变成字符串方便实用strlen()*/
for(j=;j>=;j--)
if(f[i][j]!='')
{
f[i][j+]='\0';
break;
}
while(cin>>a>>b)
{
if(a[]==''&&b[]=='')
break;
count=;
j=;
for(i=;i<=;i++)
{
if(_cmp(a,f[i])>=&&_cmp(b,f[i])<=)
count++;
if(_cmp(b,f[i])>=)
break;
}
cout<<count<<endl;
}
}
How Many Fibs?的更多相关文章
- How many Fibs?【sudt 2321】【大数的加法及其比较】
How many Fibs? Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Recall the definition of t ...
- 数论 - 高精度Fibonacci数 --- UVa 10183 : How Many Fibs ?
How many Fibs? Description Recall the definition of the Fibonacci numbers: f1 := 1 f2 := 2 fn := f n ...
- hdu 1316 How Many Fibs?
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1316 How Many Fibs? Description Recall the definition ...
- 【HDOJ】1316 How Many Fibs?
Java水了. import java.util.Scanner; import java.math.BigInteger; public class Main { public static voi ...
- HDOJ 1316 How Many Fibs?
JAVA大数.... How Many Fibs? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Jav ...
- hdu--1316--How Many Fibs?(java大数)
How Many Fibs? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- (compareTo) How Many Fibs hdu1316 && ZOJ1962
How Many Fibs? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- How many Fibs? POJ - 2413
How many Fibs? POJ - 2413 高精模板 #include<cstdio> #include<cstring> #include<algorithm& ...
- SPOJ #536. How many Fibs
Since number could be 10^100, we have to use large number processing method, in string. A simpler me ...
随机推荐
- java中的File.separator
前些天遇到一个问题,困扰了好久,现在终于解决了. 问题:上传的图片不能正确显示. 我的开发环境是在Windows下,工程在Windows下能正常部署,上传的图片也可以正常的显 示.但是把工程部署在服务 ...
- Python使用xslt提取网页数据
1,引言 在Python网络爬虫内容提取器一文我们详细讲解了核心部件:可插拔的内容提取器类gsExtractor.本文记录了确定gsExtractor的技术路线过程中所做的编程实验.这是第一部分,实验 ...
- python读取Excel
import xlrd # 读取Excel文件 workbook = xlrd.open_workbook(r'E:\2015.xls') # 读取Excel的sheet名字 sheet_names ...
- 愉快的开始 - 零基础入门学习Python000
愉快的开始 让编程改变世界 Change the world by program 为什么是Python 既然有各种各样的编程语言可以选择,小甲鱼为什么极力鼓励大家来学习Python呢? 跨平台哦亲 ...
- ES6新特性-------数组、Math和扩展操作符(续)
三.Array Array对象增加了一些新的静态方法,Array原型上也增加了一些新方法. 1.Array.from 从类数组和可遍历对象中创建Array的实例 类数组对象包括:函数中的argumen ...
- 从一道面试题谈linux下fork的运行机制
http://www.cnblogs.com/leoo2sk/archive/2009/12/11/talk-about-fork-in-linux.html
- Go代理,修改标题
- invesments 第三章 上
1. How firms issue securities: 公司如何发行股票 A. primary market: 新的股票,债券和其他的证券第一次发行的market B. ...
- LeeCode-Sqrt(x)
Implement int sqrt(int x). Compute and return the square root of x. int mySqrt(int x) { ) ; /* for(i ...
- Dynamic Flash Messages
Dynamic Flash Messages的类似软件 - 其他jQuery插件 - 开源中国社区 Dynamic Flash Messages