POJ 2413 How many Fibs?(高精度暴力)
来源:互联网 发布:淘宝的卖家中心在哪里 编辑:程序博客网 时间:2024/06/05 05:09
How many Fibs?
Time Limit: 1000MSMemory Limit: 65536KTotal Submissions: 12308Accepted: 4404
Description
Recall the definition of the Fibonacci numbers:
Given two numbers a and b, calculate how many Fibonacci numbers are in the range [a,b].
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].
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
题意
给你两个整数l,r,范围在
10100 内,问你在l~r内有多少个斐波那契数,定义Fib[1]=1,Fib[2]=2。
思路
虽然范围看起来十分大,但是由于斐波那契数增长十分快,所以到
10100 也就600个左右的数,所以直接暴力找就行了。(第一次手写高精1A..也算是一个成就吧QAQ)
Code
#pragma GCC optimize(3)#include<cstdio>#include<iostream>#include<cstring>#include<cctype>#include<string>#include<climits>#include<cmath>#include<algorithm>using namespace std;typedef long long ll;inline void readInt(int &x) { x=0;int f=1;char ch=getchar(); while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();} while(isdigit(ch))x=x*10+ch-'0',ch=getchar(); x*=f;}inline void readLong(ll &x) { x=0;int f=1;char ch=getchar(); while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();} while(isdigit(ch))x=x*10+ch-'0',ch=getchar(); x*=f;}/*================Header Template==============*/struct BigInt { int a[105],len; inline void read() { memset(a,0,sizeof a); char s[105]; scanf("%s",s+1); len=strlen(s+1); for(int i=1;i<=len;i++) a[i]=s[len-i+1]-'0'; } inline void init(ll x) { memset(a,0,sizeof a); int pos=0; while(x) { a[++pos]=x%10; x/=10; } len=pos; } inline void getlimit() { len=101; for(int i=1;i<=100;i++) a[i]=0; a[101]=1; } inline void print() { printf("Len = %d\n",len); for(int i=len;i>=1;i--) printf("%d",a[i]); puts(""); }};inline BigInt operator + (const BigInt &a,const BigInt &b) { BigInt c; c.init(0LL); c.len=max(a.len,b.len); for(int i=1;i<=c.len;i++) { c.a[i]+=a.a[i]+b.a[i]; if(c.a[i]>=10) { c.a[i]-=10; c.a[i+1]+=1; } } if(c.a[c.len+1]!=0) c.len++; return c;}inline bool operator < (const BigInt &a,const BigInt &b) {//其实这里是小于等于 if(a.len<b.len) return 1; if(a.len>b.len) return 0; for(int i=a.len;i>=1;i--) if(a.a[i]<b.a[i]) return 1; else if(a.a[i]>b.a[i]) return 0; return 1;}BigInt f[1010];BigInt l,r;int cnt=0;int main() { f[1].init(1LL); f[2].init(2LL); for(cnt=3;;cnt++) { f[cnt]=f[cnt-1]+f[cnt-2]; if(f[cnt].len>=101) break; } while(1) { l.read(); r.read(); if(l.len==1&&l.a[1]==0&&r.len==1&&r.a[1]==0) break; int ans=0; for(int i=1;i<=cnt;i++) { if(l<f[i]&&f[i]<r) ans++; if(r<f[i]) break; } printf("%d\n",ans); } return 0;}
阅读全文
0 0
- POJ 2413 How many Fibs?(高精度暴力)
- How many Fibs?(高精度)
- How many Fibs?(高精度)
- poj 2413 How many Fibs?
- POJ 2413 How many Fibs?
- POJ 2413 How many Fibs?
- POJ 2413 How many Fibs? .
- pku 2413 How many Fibs? 【java高精度】
- POJ 2413 How many Fibs? /HDOJ 1316 How Many Fibs?
- How Many Fibs? hdu1316 高精度
- hdu1316(How Many Fibs?)高精度
- (高精度运算4.7.31)POJ 2413 How many Fibs?(大数累加)
- zoj 1962 || poj 2413 How many Fibs?(大数~)
- poj 2413 java How many Fibs?
- zoj 1962 || poj 2413 How many Fibs?
- hdu 1316 poj 2413 how many Fibs
- POJ 2413 How many Fibs? 笔记
- JAVA hdu 1316 How Many Fibs?(高精度)
- vue基础动态路由,嵌套路由router-link切换
- 从今天开始写博客
- 怎么花钱能变得富有,除了读书还能这样
- Caused by: java.net.URISyntaxException: Illegal character in query at index , Target host is not sp
- 点击显示/隐藏密码
- POJ 2413 How many Fibs?(高精度暴力)
- Spring事务配置解惑
- java-mybatis generator-生成 mysql 数据库访问文件
- 错误记录--更改tomcat端口号方法,Several ports (8005, 8080, 8009)
- 【实战】5-2 用户登录相关功能开发
- 【基本算术定理 && 质因数分解】LightOJ
- 架构师之路-在Dubbo中开发REST风格的远程调用
- 运动健身行业小程序开发详解
- 1.3 事务