zoj 1828 Fibonacci Numbers
A Fibonacci sequence is calculated by adding the previous two members of the sequence, with the first two members being both 1.
f(1) = 1, f(2) = 1, f(n > 2) = f(n - 1) + f(n - 2)
Your task is to take a number as input, and print that Fibonacci number.
Sample Input
100
Sample Output
354224848179261915075
Note:
No generated Fibonacci number in excess of 1000 digits will be in the test data, i.e. f(20) = 6765 has 4 digits.
注意有多个测试样例。
代码:
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#define inf 0x3f3f3f3f
using namespace std; int n; int main() {
while(~scanf("%d",&n)) {
char s[][] = {"",""};
char *a = s[],*b = s[];
for(int i = ;i <= n;i ++) {
int d = ,j;
for(j = ;a[j];j ++) {
if(b[j]) d += b[j] - '';
d += a[j] - '';
b[j] = d % + '';
d /= ;
}
while(d) {
b[j ++] = d % + '';
d /= ;
}
b[j] = ;
swap(a,b);
}
reverse(a,a + strlen(a));
printf("%s\n",a);
}
}
zoj 1828 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个斐波那契数的 ...
- Fibonacci Numbers
Fibonacci Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- 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通项公式求,详见上一篇 ...
随机推荐
- Frame 框架的创建
Qt 创建Frame框架的例子: QFrame * frm = new QFrame(this); //创建一个框架 frm->setFrameStyle(QFrame::StyledPanel ...
- java之简单工厂
1.使用步骤 创建抽象/接口产品类,定义具体产品的公共接口方法:(产品接口类) 创建具体产品类,是继承抽象产品类的:(产品接口实现类) 创建工厂类,通过创建静态方法根据传入不同参数从而创建不同具体产品 ...
- 向Oracle 数据表中插入一条带有日期类型的数据
有一张表:batch(批次表) 表的字段如下: 第一种情况: 现在需要插入一条当前的系统时间 sql 如下: insert into batch (batch_id, cus_id, batch_nu ...
- FindBugs详解
欢迎和大家交流技术相关问题: 邮箱: jiangxinnju@163.com 博客园地址: http://www.cnblogs.com/jiangxinnju GitHub地址: https://g ...
- linux第七章读书笔记
Vim编辑器 Vim 仅仅通过键盘来在插入和执行命令等多种模式之间切换.这使得Vim可以不用进行菜单或者鼠标操作,并且最小化组合键的操作,对文字录入员或者程序员可以大大增强速度和效率. CHAPTER ...
- Kali视频学习21-25
Kali视频学习21-25 (21)密码攻击之在线攻击工具 一.cewl可以通过爬行网站获取关键信息创建一个密码字典. 二.CAT (Cisco-Auditing-Tool)很小的安全审计工具,扫描C ...
- mysql绑定参数bind_param原理以及防SQL注入
假设我们的用户表中存在一行.用户名字段为username.值为aaa.密码字段为pwd.值为pwd.. 下面我们来模拟一个用户登录的过程.. <?php $username = "aa ...
- Execution Order for the ApiController
Execution Order for the ApiController Assuming the request goes into the ApiController scope, the op ...
- Asp.net下拉树实现(Easy UI ComboTree)
场景描述:某个公司有多个部门并且部门存在子部门,通过一个下拉框选取多个部门,但是如果某个部门的子部门被全部选择,则只取该部门,而忽略子部门.(叶子节点全被选中时,只取父节点) 知识点:ComboTre ...
- Flask: socket.error: [Errno 48] Address already in use 问题
参考: Mac OSX 解决socket.error: [Errno 48] Address already in use问题 Mac OS X中解决socket.error: [Errno 48] ...