Fibonacci
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 0 Sample Output 0 思路:没得说,矩阵快速幂 代码如下: #include <iostream> |
相关文章
- 黑马入学基础测试(三)求斐波那契数列第n项,n<30,斐波那契数列前10项为 1,1,2,3,5,8,13,21,34,55
- 求前n项的斐波那契数列、求两个数的最小公倍数、求两个数的最大公约数
- Python实现求解斐波那契第n项的解法(包括矩阵乘法+快速幂)
- C语言求Fibonacci斐波那契数列通项问题的解法总结
- hdu 4549 M斐波那契数列(快速幂 矩阵快速幂 费马小定理)
- HDU——4549M斐波那契数列(矩阵快速幂+快速幂+费马小定理)
- POJ 3070(求斐波那契数 矩阵快速幂)
- java数学归纳法非递归求斐波那契数列的方法
- 斐波那契数列 优化矩阵求法实例
- 使用python求斐波那契数列中第n个数的值示例代码