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 ...
随机推荐
- web中的中文字体的英文名称
自从font-face出现以后,字体样式就不再是web开发者的难题了,但是对于移动端的中文来说,问题还是存在的,因为中文文件大小最少要3M+,即使选择性的加载某个字的字体,那也会出现不易替换的问题,所 ...
- MAC OS中使用ll,la命令
在linux下习惯了使用ll.la等ls别名 用mac os发现没有这样的命令,很不方便. 其实只要在用户目录下建立一个脚本“.bash_profile”,并输入以下内容即可:alias ll='ls ...
- Python学习笔记五,函数及其参数
在Python中如何自定义函数:其格式为 def 函数名(函数参数): 内容
- 负载均衡集群之LVS配置命令
ipvs/ipvsadm 添加集群服务--> ipvsadm -A|E -t|u|f VIP[:Port] -s scheduler [-p timeout] [-O] [-M netmask] ...
- 实现AT24C02的数据读写操作
/*************************************************************** 功能:11:32 2008-6-27 作者:SG 时间:2004-03 ...
- rpm包制作
ubuntu下先下载sudo apt-get install rpm就行了. 然后测试下rpm和rpmbuild命令都是存在的.好了,OK. rpm安装包的制作有严格的自定义的路径,这个路径是在/us ...
- bzoj1648 [Usaco2006 Dec]Cow Picnic 奶牛野餐
Description The cows are having a picnic! Each of Farmer John's K (1 <= K <= 100) cows is graz ...
- 【C语言用法】C语言的函数“重载”
由于平时很少用到__attribute__定义函数或者变量的符号属性,所以很难想象C语言可以向C++一样进行函数或者变量的重载. 首先,复习一下有关强符号与弱符号的概念和编译器对强弱符号的处理规则: ...
- PHP 表单验证 - 完成表单实例
------------------------------------------------------------------------------------------- 本节展示如何在用 ...
- Python高阶函数
在Python中,函数名也是一个变量,可以进行赋值 高阶函数是至少满足下列一个条件的函数: 接受一个或多个函数作为输入 输出一个函数 函数名也可以作为函数参数,还可以作为函数返回值 def f(n) ...