题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=1316

How Many Fibs?

Description

Recall the definition of the Fibonacci numbers:
$f_1 := 1$
$f_2 := 2$
$f_n := f_{n-1} + f_{n-2} \ \ (3 \leq n)$

Given two numbers a and b, calculate how many Fibonacci numbers are in the range $[a, b]$.

Input

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 \leq b \leq 10^{100}$ The numbers a and b are given with no superfluous leading zeros.

Output

For each test case output on a single line the number of $Fibonacci$ numbers $f_i$ with $a \leq f_i \leq b. $

SampleInput

10 100

1234567890 9876543210

0 0

SampleOutput

5

4

 #include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cassert>
#include<cstdio>
#include<vector>
#include<string>
#include<set>
using std::cin;
using std::max;
using std::cout;
using std::endl;
using std::string;
using std::vector;
using std::istream;
using std::ostream;
#define N 510
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define iter(c) decltype((c).begin())
#define cls(arr,val) memset(arr,val,sizeof(arr))
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define fork(i, k, n) for (int i = (int)k; i <= (int)n; i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
struct BigN {
typedef unsigned long long ull;
static const int Max_N = ;
int len, data[Max_N];
BigN() { memset(data, , sizeof(data)), len = ; }
BigN(const int num) {
memset(data, , sizeof(data));
*this = num;
}
BigN(const char *num) {
memset(data, , sizeof(data));
*this = num;
}
void clear() { len = , memset(data, , sizeof(data)); }
BigN& clean(){ while (len > && !data[len - ]) len--; return *this; }
string str() const {
string res = "";
for (int i = len - ; ~i; i--) res += (char)(data[i] + '');
if (res == "") res = "";
res.reserve();
return res;
}
BigN operator = (const int num) {
int j = , i = num;
do data[j++] = i % ; while (i /= );
len = j;
return *this;
}
BigN operator = (const char *num) {
len = strlen(num);
for (int i = ; i < len; i++) data[i] = num[len - i - ] - '';
return *this;
}
BigN operator + (const BigN &x) const {
BigN res;
int n = max(len, x.len) + ;
for (int i = , g = ; i < n; i++) {
int c = data[i] + x.data[i] + g;
res.data[res.len++] = c % ;
g = c / ;
}
return res.clean();
}
BigN operator * (const BigN &x) const {
BigN res;
int n = x.len;
res.len = n + len;
for (int i = ; i < len; i++) {
for (int j = , g = ; j < n; j++) {
res.data[i + j] += data[i] * x.data[j];
}
}
for (int i = ; i < res.len - ; i++) {
res.data[i + ] += res.data[i] / ;
res.data[i] %= ;
}
return res.clean();
}
BigN operator * (const int num) const {
BigN res;
res.len = len + ;
for (int i = , g = ; i < len; i++) res.data[i] *= num;
for (int i = ; i < res.len - ; i++) {
res.data[i + ] += res.data[i] / ;
res.data[i] %= ;
}
return res.clean();
}
BigN operator - (const BigN &x) const {
assert(x <= *this);
BigN res;
for (int i = , g = ; i < len; i++) {
int c = data[i] - g;
if (i < x.len) c -= x.data[i];
if (c >= ) g = ;
else g = , c += ;
res.data[res.len++] = c;
}
return res.clean();
}
BigN operator / (const BigN &x) const {
BigN res, f = ;
for (int i = len - ; ~i; i--) {
f *= ;
f.data[] = data[i];
while (f >= x) {
f -= x;
res.data[i]++;
}
}
res.len = len;
return res.clean();
}
BigN operator % (const BigN &x) {
BigN res = *this / x;
res = *this - res * x;
return res;
}
BigN operator += (const BigN &x) { return *this = *this + x; }
BigN operator *= (const BigN &x) { return *this = *this * x; }
BigN operator -= (const BigN &x) { return *this = *this - x; }
BigN operator /= (const BigN &x) { return *this = *this / x; }
BigN operator %= (const BigN &x) { return *this = *this % x; }
bool operator < (const BigN &x) const {
if (len != x.len) return len < x.len;
for (int i = len - ; ~i; i--) {
if (data[i] != x.data[i]) return data[i] < x.data[i];
}
return false;
}
bool operator >(const BigN &x) const { return x < *this; }
bool operator<=(const BigN &x) const { return !(x < *this); }
bool operator>=(const BigN &x) const { return !(*this < x); }
bool operator!=(const BigN &x) const { return x < *this || *this < x; }
bool operator==(const BigN &x) const { return !(x < *this) && !(x > *this); }
friend istream& operator >> (istream &in, BigN &x) {
string src;
in >> src;
x = src.c_str();
return in;
}
friend ostream& operator << (ostream &out, const BigN &x) {
out << x.str();
return out;
}
}A[N + ], k1, k2;
inline void init() {
A[] = , A[] = ;
fork(i, , N) A[i] = A[i - ] + A[i - ];
}
int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w+", stdout);
#endif
init();
char str1[N], str2[N];
while (~scanf("%s %s", str1, str2)) {
if (str1[] == '' && str2[] == '') break;
int ans = ;
k1 = str1, k2 = str2;
fork(i, , N) { if (k1 <= A[i] && A[i] <= k2) ans++; }
printf("%d\n", ans);
k1.clear(), k2.clear();
}
return ;
}

hdu 1316 How Many Fibs?的更多相关文章

  1. hdu 1316 How many Fibs?(高精度斐波那契数)

    //  大数继续 Problem Description Recall the definition of the Fibonacci numbers:  f1 := 1  f2 := 2  fn : ...

  2. HDU 1316 How Many Fibs?(java,简单题,大数)

    题目 /** * compareTo:根据该数值是小于.等于.或大于 val 返回 -1.0 或 1: public int compareTo(BigInteger val) 将此 BigInteg ...

  3. hdu 1316 How Many Fibs? (模拟高精度)

    题目大意: 问[s,e]之间有多少个 斐波那契数. 思路分析: 直接模拟高精度字符串的加法和大小的比較. 注意wa点再 s 能够从 0 開始 那么要在推断输入结束的时候注意一下. #include & ...

  4. HDU 1316 (斐波那契数列,大数相加,大数比较大小)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1316 Recall the definition of the Fibonacci numbers: ...

  5. 【HDOJ】1316 How Many Fibs?

    Java水了. import java.util.Scanner; import java.math.BigInteger; public class Main { public static voi ...

  6. HDOJ 1316 How Many Fibs?

    JAVA大数.... How Many Fibs? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Jav ...

  7. hdu 1316(大整数)

    How Many Fibs? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  8. HDU高精度总结(java大数类)

      HDU1002   A + B Problem II [题意]大数相加 [链接]http://acm.hdu.edu.cn/showproblem.php?pid=1002 Sample Inpu ...

  9. Java Java Java

    学下java 的大数该怎么用>< hdu 1023 Train Problem II 求 卡特兰 数 诶...不记得卡特兰数的我眼泪掉下来 第一次用 java 大数 有点激动...> ...

随机推荐

  1. 慕课网-安卓工程师初养成-2-9 Java中的自动类型转换

    来源:http://www.imooc.com/code/1236 在 Java 程序中,不同的基本数据类型的数据之间经常需要进行相互转换.例如: , 代码中 int 型变量 score1 可以直接为 ...

  2. vb 取得桌面路径

    txtPath.Text = System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop)

  3. LARGE_INTEGER

    #include <windows.h> int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR ipCm ...

  4. dell 网络产品线

    https://en.wikipedia.org/wiki/Dell_Networking_Operating_System http://topics-cdn.dell.com/pdf/ DNOS ...

  5. sql server命名规范

    命名规范 表 表名如Order/UserAccout 符合以下规范: 1.     统一采用单数形式,反对Orders 2.     首字母大写,多个单词的话,单词首字母大写,反对order/User ...

  6. SQL:判断某些元素是否存在及创建的SQL语句

    --判断某个存储过程是否存在if exists (select * from sysobjects where id = object_id(N'[p_CreateTable]') and OBJEC ...

  7. linux设备分类

    网络设备:常见的有以太网卡.CAN总线.WIFI.蓝牙 重要的结构体: net_device:用于描述网络设备的属性,为上层提供一个统一的操作接口.网络设备的驱动实际上就是填充此结构体,实现其中的各种 ...

  8. Android IOS WebRTC 音视频开发总结(二十)-- 自由职业

    咋看标题感觉与WebRTC和音视频无关,其实有着很大的关联,文章来自博客园RTC.Blacker,转载请说明出处. 背景: 一方面因为对开发人员比较了解,不喜欢约束,喜欢自由自在,所以我们向往自由职业 ...

  9. Java设计模式(Design Patterns In Java)读书摘要——第1章 绪论

    为何需要模式 模式是做事的方法,是实现目标,研磨技术的方法.通俗点说,模式是为了解决某个行业的某个问题的有效的方法或技艺. 为何需要设计模式 为了提升代码的水准,是代码变得简洁而易用.模式是一种思想, ...

  10. 搭建高性能计算环境(七)、应用软件的安装之MS

    1,上传软件包MaterialsStudio70.tgz.msi_7.lic到服务器上. 2,安装ms一般会创建一个普通用户msi,软件安装在msi账号下. 创建用户msi: useradd msi ...