高精度推出大概600项fabi数,就包含了题目的数据范围,对于每组a,b,从1到600枚举res[i]即可

可以直接JAVA大数。我自己时套了C++高精度的版

JAVA 复制别人的

import java.math.BigInteger;
import java.util.Scanner; public class Main {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
BigInteger[] f = new BigInteger[600];
f[0] = new BigInteger("1");
f[1] = new BigInteger("2");
for(int i = 2; i < 600; i ++)
f[i] = f[i - 1].add(f[i - 2]);
for(;;)
{
BigInteger a, b;
int res = 0;
a = cin.nextBigInteger();
b = cin.nextBigInteger();
if(a.compareTo(BigInteger.ZERO) == 0 && b.compareTo(BigInteger.ZERO) == 0)
break;
for(int i = 0; i < 600; i ++)
if(f[i].compareTo(a) != -1 && f[i].compareTo(b) != 1)
res ++;
System.out.println(res);
}
}
}

C++

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b) {return a % b == ? b : gcd(b, a % b);}
const int numlen=;
struct bign {
int len, s[numlen];
bign() {
memset(s, , sizeof(s));
len = ;
}
bign(int num) { *this = num; }
bign(const char *num) { *this = num; }
bign operator = (const int num) {
char s[numlen];
sprintf(s, "%d", num);
*this = s;
return *this;
}
bign operator = (const char *num) {
len = strlen(num);
while(len > && num[] == '') num++, len--;
for(int i = ;i < len; i++) s[i] = num[len-i-] - '';
return *this;
} void deal() {
while(len > && !s[len-]) len--;
} bign operator + (const bign &a) const {
bign ret;
ret.len = ;
int top = max(len, a.len) , add = ;
for(int i = ;add || i < top; i++) {
int now = add;
if(i < len) now += s[i];
if(i < a.len) now += a.s[i];
ret.s[ret.len++] = now%;
add = now/;
}
return ret;
}
bign operator - (const bign &a) const {
bign ret;
ret.len = ;
int cal = ;
for(int i = ;i < len; i++) {
int now = s[i] - cal;
if(i < a.len) now -= a.s[i];
if(now >= ) cal = ;
else {
cal = ; now += ;
}
ret.s[ret.len++] = now;
}
ret.deal();
return ret;
}
bign operator * (const bign &a) const {
bign ret;
ret.len = len + a.len;
for(int i = ;i < len; i++) {
for(int j = ;j < a.len; j++)
ret.s[i+j] += s[i]*a.s[j];
}
for(int i = ;i < ret.len; i++) {
ret.s[i+] += ret.s[i]/;
ret.s[i] %= ;
}
ret.deal();
return ret;
} bign operator * (const int num) {
// printf("num = %d\n", num);
bign ret;
ret.len = ;
int bb = ;
for(int i = ;i < len; i++) {
int now = bb + s[i]*num;
ret.s[ret.len++] = now%;
bb = now/;
}
while(bb) {
ret.s[ret.len++] = bb % ;
bb /= ;
}
ret.deal();
return ret;
} bign operator / (const bign &a) const {
bign ret, cur = ;
ret.len = len;
for(int i = len-;i >= ; i--) {
cur = cur*;
cur.s[] = s[i];
while(cur >= a) {
cur -= a;
ret.s[i]++;
}
}
ret.deal();
return ret;
} bign operator % (const bign &a) const {
bign b = *this / a;
return *this - b*a;
} bign operator += (const bign &a) { *this = *this + a; return *this; }
bign operator -= (const bign &a) { *this = *this - a; return *this; }
bign operator *= (const bign &a) { *this = *this * a; return *this; }
bign operator /= (const bign &a) { *this = *this / a; return *this; }
bign operator %= (const bign &a) { *this = *this % a; return *this; } bool operator < (const bign &a) const {
if(len != a.len) return len < a.len;
for(int i = len-;i >= ; i--) if(s[i] != a.s[i])
return s[i] < a.s[i];
return false;
}
bool operator > (const bign &a) const { return a < *this; }
bool operator <= (const bign &a) const { return !(*this > a); }
bool operator >= (const bign &a) const { return !(*this < a); }
bool operator == (const bign &a) const { return !(*this > a || *this < a); }
bool operator != (const bign &a) const { return *this > a || *this < a; } string str() const {
string ret = "";
for(int i = ;i < len; i++) ret = char(s[i] + '') + ret;
return ret;
}
};
istream& operator >> (istream &in, bign &x) {
string s;
in >> s;
x = s.c_str();
return in;
}
ostream& operator << (ostream &out, const bign &x) {
out << x.str();
return out;
}
bign res[];
bign a,b;
void init()
{
res[]="";
res[]="";
for (int i=;i<;i++)
res[i]=res[i-]+res[i-];
}
int main()
{
init();
while (cin>>a>>b)
{
if (a=="" && b=="") break;
int ans=;
for (int i=;i<;i++)
if (res[i]>=a && res[i]<=b) ans++;
printf("%d\n",ans);
}
return ;
}

UVA 10183 How Many Fibs?的更多相关文章

  1. 数论 - 高精度Fibonacci数 --- UVa 10183 : How Many Fibs ?

    How many Fibs? Description Recall the definition of the Fibonacci numbers: f1 := 1 f2 := 2 fn := f n ...

  2. UVA题目分类

    题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...

  3. (Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO

    http://www.cnblogs.com/sxiszero/p/3618737.html 下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年 ...

  4. ACM训练计划step 1 [非原创]

    (Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO 下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成 ...

  5. 算法竞赛入门经典+挑战编程+USACO

    下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成.打牢基础,厚积薄发. 一.UVaOJ http://uva.onlinej ...

  6. uva 1354 Mobile Computing ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5

  7. UVA 10564 Paths through the Hourglass[DP 打印]

    UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...

  8. UVA 11404 Palindromic Subsequence[DP LCS 打印]

    UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...

  9. UVA&&POJ离散概率与数学期望入门练习[4]

    POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...

随机推荐

  1. debian8.2安装kubernetes

    master上通过kubeadm安装Kubernetes 添加国内阿里源后安装kubeadm: deb https://mirrors.aliyun.com/kubernetes/apt/ kuber ...

  2. kaldi GMM模型解码指令 gmm-latgen-faster详解

    目录 - 作用: - 用法: - 可选项及含义: - 使用实例: - 作用: Generate lattices using GMM-based model. 生成基于GMM模型的lattice词格) ...

  3. 可以随着SeekBar滑块滑动显示的Demo

    //关于Seek的自定义样式,之前也有总结过,但是,一直做不出随着滑块移动的效果,查询了很多资料终于解决了这个问题,现在把代码写出来有bug的地方 希望大家批评指正. Step 1 :自定义一个Vie ...

  4. Go基础篇【第6篇】: 内置库模块 flag

    import "flag" flag包实现了命令行参数的解析.每个参数认为一条记录,根据实际进行定义,到一个set集合.每条都有各自的状态参数. 在使用flag时正常流程: 1.  ...

  5. HDU 3269 P2P File Sharing System(模拟)(2009 Asia Ningbo Regional Contest)

    Problem Description Peer-to-peer(P2P) computing technology has been widely used on the Internet to e ...

  6. windows下连接hadoop运行eclipse报错Permission denied:

    这是权限问题,试了一下同时也不能在hdfs创建文件夹. 解决: 修改如下hadoop的配置文件:etc/hadoop/hdfs-site.xml,如没有的话可以添加上. <property> ...

  7. Linux TCP协议使用的变量

    Linux /proc/sys/net/ipv4/* 变量 TCP变量:somaxconn - INTEGER    listen()的backlog参数的上限,在用户态为SOMAXCONN.默认是1 ...

  8. lintcode-74-第一个错误的代码版本

    74-第一个错误的代码版本 代码库的版本号是从 1 到 n 的整数.某一天,有人提交了错误版本的代码,因此造成自身及之后版本的代码在单元测试中均出错.请找出第一个错误的版本号. 你可以通过 isBad ...

  9. JMS实战——ActiveMQ实现Pub-Sub

    前言 上篇博客<JMS实战--ActiveMQ>介绍了ActiveMQ的安装,并实现了简单的PTP模型.这篇博客我们来看一下Pub-Sub模型,之后来总结一下JMS. 实现 项目结构 其中 ...

  10. Aspose.Pdf合并PDF文件

    使用Aspose.Pdf类库,有很多种方法可以合并PDF文件,这里简单介绍小生见到的几种: Doucment.Pages.Add PdfFileEditor.Append PdfFileEditor. ...