Fibonacci Numbers
| Fibonacci Numbers | 
| Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) | 
| Total Submission(s): 81 Accepted Submission(s): 46 | 
| Problem Description  The Fibonacci sequence is the sequence of numbers such that every element is equal to the sum of the two previous elements, except for the first two elements f0 and f1 which are respectively zero and one. What is the numerical value of the nth Fibonacci number? | 
| Input 							For each test case, a line will contain an integer i between 0 and 108 inclusively, for which you must compute the ith Fibonacci number fi. Fibonacci numbers get large pretty quickly, so whenever the answer has more than 8 digits, output only the first and last 4 digits of the answer, separating the two parts with an ellipsis (“...”).
 There is no special way to denote the end of the of the input, simply stop when the standard input terminates (after the EOF). | 
| Sample Input 0 | 
| Sample Output 0 | 
| Source IPCP 2005 Northern Preliminary for Northeast North-America | 
| Recommend lcy | 
/*
题意:求第n个斐波那契数列的值,只需要前四位,后四位 初步思路:后四位好说,膜一下就行了重要的就是前四位.总共1e8的时间,感觉用大数爆都会超时 #补充:后四位矩阵膜10000就行了,前四位可以用通项公式取对数的方法求。 */
#include<bits/stdc++.h>
#define ll long long
#define mod 10000
using namespace std;
/********************************矩阵模板**********************************/
class Matrix {
public:
int a[][]; void init(int x) {
memset(a,,sizeof(a));
if (x)
for (int i = ; i < ; i++)
a[i][i] = ;
} Matrix operator +(Matrix b) {
Matrix c;
for (int i = ; i < ; i++)
for (int j = ; j < ; j++)
c.a[i][j] = (a[i][j] + b.a[i][j]) % mod;
return c;
} Matrix operator +(int x) {
Matrix c = *this;
for (int i = ; i < ; i++)
c.a[i][i] += x;
return c;
} Matrix operator *(Matrix b)
{
Matrix p;
p.init();
for (int i = ; i < ; i++)
for (int j = ; j < ; j++)
for (int k = ; k < ; k++)
p.a[i][j] = (p.a[i][j] + (a[i][k]*b.a[k][j])%mod) % mod;
return p;
} Matrix power_1(int t) {
Matrix Frist,p = *this;
Frist.init();
while (t) {
if (t & )
Frist=Frist*p;
p = p*p;
t >>= ;
}
return Frist;
} Matrix power_2(Matrix a,Matrix b,int x){
while(x){
if(x&){
b=a*b;
}
a=a*a;
x>>=;
}
return b;
}
};
/********************************矩阵模板**********************************/
Matrix unit,init;
ll f[];
ll n;
int main(){
// freopen("in.txt","r",stdin);
f[]=;
f[]=;
for(int i=;i<;i++){
f[i]=f[i-]+f[i-];
}
while(scanf("%lld",&n)!=EOF){
if(n<){
printf("%lld\n",f[n]);
continue;
}
unit.a[][]=;
unit.a[][]=;
unit.a[][]=;
unit.a[][]=; init.a[][]=;
init.a[][]=;
init.a[][]=;
init.a[][]=; init=init.power_1(n-);//有问题
unit=unit*init;
int Last=unit.a[][]; long double Frist=-0.5 * log(5.0) / log(10.0) + ((long double)n) * log((sqrt(5.0)+1.0)/2.0) / log(10.0);
Frist-=floor(Frist);
Frist=pow(,Frist);
while(Frist<)
Frist*=;
printf("%d...%04d\n",(int) Frist,Last);
}
return ;
}
Fibonacci Numbers的更多相关文章
- codeforces 446C DZY Loves Fibonacci Numbers(数学 or 数论+线段树)(两种方法)
		In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation F1 ... 
- Codeforces 446-C  DZY Loves Fibonacci Numbers 同余 线段树 斐波那契数列
		C. DZY Loves Fibonacci Numbers time limit per test 4 seconds memory limit per test 256 megabytes inp ... 
- cf446C DZY Loves Fibonacci Numbers
		C. DZY Loves Fibonacci Numbers time limit per test 4 seconds memory limit per test 256 megabytes inp ... 
- Codeforces Round #FF 446 C. DZY Loves Fibonacci Numbers
		參考:http://www.cnblogs.com/chanme/p/3843859.html 然后我看到在别人的AC的方法里还有这么一种神方法,他预先设定了一个阈值K,当当前的更新操作数j<K ... 
- HDU 3117 Fibonacci Numbers(围绕四个租赁斐波那契,通过计++乘坐高速动力矩阵)
		HDU 3117 Fibonacci Numbers(斐波那契前后四位,打表+取对+矩阵高速幂) ACM 题目地址:HDU 3117 Fibonacci Numbers 题意: 求第n个斐波那契数的 ... 
- Codeforces446C - DZY Loves Fibonacci Numbers
		Portal Description 给出一个\(n(n\leq3\times10^5)\)个数的序列,进行\(m(m\leq3\times10^5)\)次操作,操作有两种: 给区间\([L,R]\) ... 
- UVA 11582 Colossal Fibonacci Numbers(数学)
		Colossal Fibonacci Numbers 想先说下最近的状态吧,已经考完试了,这个暑假也应该是最后刷题的暑假了,打完今年acm就应该会退了,但是还什么都不会呢? +_+ 所以这个暑假,一定 ... 
- HDU 3117 Fibonacci Numbers(矩阵)
		Fibonacci Numbers [题目链接]Fibonacci Numbers [题目类型]矩阵 &题解: 后4位是矩阵快速幂求,前4位是用log加Fibonacci通项公式求,详见上一篇 ... 
- [CodeForces - 447E] E - DZY Loves Fibonacci Numbers
		E DZY Loves Fibonacci Numbers In mathematical terms, the sequence Fn of Fibonacci numbers is define ... 
随机推荐
- Coder的好伙伴Github
			网络越来越发达,各式各样的网盘.云存储也走进日常生活, 在老师的指导下,我第一次接触了GitHub. 什么是Github? Github是一个基于git的代码托管平台,付费用户可以建私人仓库,我们一 ... 
- oracle 权限
			一.介绍这一部分我们主要看看oracle中如何管理权限和角色,权限和角色的区别在哪里.当刚刚建立用户时,用户没有任何权限,也不能执行任何操作.如果要执行某种特定的数据库操作,则必须为其授予系统的权限: ... 
- 献身说法---修复bug时的一些小技巧
			最近,修复了项目当中的一些bug,觉着有些思路可以分享出来供大家借鉴. 场景一 开发环境中系统正常运行,测试环境中,部分机器未能正常运行. 解决过程:远程连接了测试环境中的机器,观察了系统的运行情况, ... 
- C#单例测试(懒汉式双锁保证线程安全)
			单例模式的概念 单例模式的意思就是只有一个实例.单例模式确保某一个类只有一个实例,而且自行实例化并向整个系统提供这个实例.这个类称为单例类. 关键点: 这个类只有一个实例,这是最基本的 它必须自行创建 ... 
- python文件名和文件路径操作
			Readme: 在日常工作中,我们常常涉及到有关文件名和文件路径的操作,在python里的os标准模块为我们提供了文件操作的各类函数,本文将分别介绍"获得当前路径""获得 ... 
- jQuery: Callbacks
			jQuery 中提供了一个Callback的工具类Callbacks,它提供了一个Callback Chain.使用它可以在一个chain上来执行相关操作.它也是jQuery中的ajax, Defer ... 
- Oculus关于Internal Error:OVR53225466报错解决方法
			安装Oculus过程中可能会出现Internal Error:OVR53225466报错提示,如附件所示: 解决方法:修改hosts文件 操作方法: (1)以管理员方式打开记事本: (2)打开C:\W ... 
- spring jar包
			org.springframework.aop- 3.0.0.RELEASE--------------------Spring的面向切面编程,提供AOP(面向切面编程)实现 org.springfr ... 
- Spring Framework 5.0 新特性
			Spring Framework 5.0是在Spring Framework 4.0之后将近四年内一次重大的升级. 在这个时间框架内,主要的发展之一就是Spring Boot项目的演变. Spring ... 
- 数据分析前戏:ipython使用技巧(上)
			不一定非得使用Jupyter Notebook,试试ipython命令行 安装 ipython 我只试过Windows 10环境下的. 1.安装python安装包之后,应该就有ipython了. 2. ... 
