博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj3070矩阵快速幂
阅读量:6941 次
发布时间:2019-06-27

本文共 1500 字,大约阅读时间需要 5 分钟。

Fibonacci
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 7752   Accepted: 5501

Description

In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn − 1 + Fn − 2 for n ≥ 2. For example, the first ten terms of the Fibonacci sequence are:

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, …

An alternative formula for the Fibonacci sequence is

.

Given an integer n, your goal is to compute the last 4 digits of Fn.

Input

The input test file will contain multiple test cases. Each test case consists of a single line containing n (where 0 ≤ n ≤ 1,000,000,000). The end-of-file is denoted by a single line containing the number −1.

Output

For each test case, print the last four digits of Fn. If the last four digits of Fn are all zeros, print ‘0’; otherwise, omit any leading zeros (i.e., print Fn mod 10000).

Sample Input

099999999991000000000-1

Sample Output

0346266875
1 #include 
2 #include
3 #include
4 #include
5 #include
6 7 using namespace std; 8 int N; 9 struct matrix10 {11 int a[2][2];12 }origin,res;13 matrix multiply(matrix x,matrix y)14 {15 matrix temp;16 memset(temp.a,0,sizeof(temp.a));17 for(int i=0;i
>=1;42 origin=multiply(origin,origin);43 }44 }45 int main()46 {47 N=2;48 int n;49 while(cin>>n)50 {51 if(n==-1)52 break;53 if(n)54 calc(n-1);55 if(n)56 cout<
<
View Code

 

转载于:https://www.cnblogs.com/ERKE/p/3272728.html

你可能感兴趣的文章
为 Nginx 添加 HTTP 基本认证(HTTP Basic Authentication)
查看>>
gulp使用ES6
查看>>
ECUG Con 邀您共议服务端开发最深度实践
查看>>
关于优惠券功能设计之我的见解
查看>>
JavaScript中的函数式编程二(翻译)
查看>>
Javascript的异步编程:Promise
查看>>
荣誉,还是苦逼?| 也议全栈工程师和DevOps
查看>>
gulp详细基础教程
查看>>
CSS基础篇-- position属性讲解
查看>>
Python2.x的编码问题
查看>>
开源编辑器 Atom 简化代码审查过程
查看>>
每秒聚合5亿个指标,Uber 开源大规模指标平台 M3
查看>>
中国航天局向荷兰、德国等移交嫦娥四号载荷数据,并同时发布其他项目合作机会公告 ...
查看>>
Spring MVC原理
查看>>
图灵奖得主长文报告:是什么开启了计算机架构的新黄金十年?(上) ...
查看>>
pseudo tty破除无法自动输入密码的限制
查看>>
阿里云财务软件好会计-好会计财务管理系统介绍 ...
查看>>
推荐:一款分布式的对象存储服务
查看>>
WordPress免费插件的选择指南
查看>>
浮云朝露 2018
查看>>