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的更多相关文章

  1. codeforces 446C DZY Loves Fibonacci Numbers(数学 or 数论+线段树)(两种方法)

    In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation F1 ...

  2. 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 ...

  3. cf446C DZY Loves Fibonacci Numbers

    C. DZY Loves Fibonacci Numbers time limit per test 4 seconds memory limit per test 256 megabytes inp ...

  4. Codeforces Round #FF 446 C. DZY Loves Fibonacci Numbers

    參考:http://www.cnblogs.com/chanme/p/3843859.html 然后我看到在别人的AC的方法里还有这么一种神方法,他预先设定了一个阈值K,当当前的更新操作数j<K ...

  5. HDU 3117 Fibonacci Numbers(围绕四个租赁斐波那契,通过计++乘坐高速动力矩阵)

    HDU 3117 Fibonacci Numbers(斐波那契前后四位,打表+取对+矩阵高速幂) ACM 题目地址:HDU 3117 Fibonacci Numbers 题意:  求第n个斐波那契数的 ...

  6. Fibonacci Numbers

    Fibonacci Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...

  7. Codeforces446C - DZY Loves Fibonacci Numbers

    Portal Description 给出一个\(n(n\leq3\times10^5)\)个数的序列,进行\(m(m\leq3\times10^5)\)次操作,操作有两种: 给区间\([L,R]\) ...

  8. UVA 11582 Colossal Fibonacci Numbers(数学)

    Colossal Fibonacci Numbers 想先说下最近的状态吧,已经考完试了,这个暑假也应该是最后刷题的暑假了,打完今年acm就应该会退了,但是还什么都不会呢? +_+ 所以这个暑假,一定 ...

  9. HDU 3117 Fibonacci Numbers(矩阵)

    Fibonacci Numbers [题目链接]Fibonacci Numbers [题目类型]矩阵 &题解: 后4位是矩阵快速幂求,前4位是用log加Fibonacci通项公式求,详见上一篇 ...

随机推荐

  1. 团队 作业6--展示(alpha阶段)

    团队作业6--展示博客(alpha阶段) 一.团队信息 团队码云地址: https://gitee.com/kezhiqing/soft_team_blog 成员介绍: 个人博客地址 团队成员 个人博 ...

  2. 5makefile

    makefile编译多个可执行文件1: 多个 C 文件编译成不同的目标文件2: 多个 C 文件编译成 一个目标文件 注意:makefile的文件名的三种形式(优先级排序)makefile>Mak ...

  3. Hello 2019 Solution

    A. Gennady and a Card Game 签到. #include <bits/stdc++.h> using namespace std; ], t[]; bool solv ...

  4. Python 非递归遍历图

    class Queue: def __init__(self,max_size): self.max_size = int(max_size) self.queue = [] def put(self ...

  5. Web安全之BurpSuite抓取HTTPS请求

    出现了问题,第一步要干什么呢? 当然是要去官方网站去找FAQ和help,先来练习一下英语 https://portswigger.net/burp/help/proxy_options_install ...

  6. GreenOpenPaint的实现(二)打开显示图片

    1.DOC中添加,核心图片文件保存在这里.之所以不用Mat,是因为CVVImage有更好的输入输出函数. 我这里直接使用了public public: CvvImage m_image; 2.重载打开 ...

  7. BZOj 墨墨的等式(转化为最短路)题解

    题意:中文题意不解释... 思路:这道题居然可以转化为最短路orz,要等式有非负整数解,我们可以转化一下:每个ai不限数量,问你能用ai数组拼出多少个Bmin~Bmax范围内的数,有点像完全背包的感觉 ...

  8. NO.1 在Eclipse中安装Maven插件安装详解

    前言 本来是没打算写博客的,作为一个13年毕业的菜鸟,自认为水平太渣写不出什么好文章,但是前些日子看到一篇鼓励性质的文章说,技术人员的成长靠的就是点点滴滴的积累,博客内容不一定包含多么高深的内容,但是 ...

  9. linux find/grep 与cat联合使用

    find ./ -name  file_name.txt   | xargs cat >> file_name.txt

  10. sapply

    列表并非总是存储结果的最佳容器.有时,我们希望将结果放在一个向量或者矩阵中.sapply( )函数可以根据结果的结构将其合理简化.假设,我们将平方运算应用到 1:10 的每个元素上.如果使用 lapp ...