HDU 1568 Fibonacci
2011-11-28 20:31
281 查看
http://acm.hdu.edu.cn/showproblem.php?pid=1568
与 HDU 1060 Leftmost Digit 差不多
求后几位的话,可以构造矩阵相乘,二分求冪
求前几位,不需要,直接运用数学公式和对数的性质来求
斐波那契数列通项公式
代码
与 HDU 1060 Leftmost Digit 差不多
求后几位的话,可以构造矩阵相乘,二分求冪
求前几位,不需要,直接运用数学公式和对数的性质来求
斐波那契数列通项公式
代码
#include <stdio.h> #include <math.h> int main() { const int N=21; int f ={0,1}; for (int i=2;i<N;i++) f[i]=f[i-1]+f[i-2]; int n; while (scanf("%d",&n)!=EOF) { if (n<N) { printf("%d\n",f ); continue; } double e,a; e=log10(1/sqrt(5))+n*log10((1+sqrt(5))/2); a=pow(10.0,e-floor(e)); printf("%d\n",(int)(a*1000)); } }
相关文章推荐
- HDU 1568 Fibonacci ★(取科学计数法)
- HDU 1568 Fibonacci
- 数论(fabonacci数列) hdu-1568-Fibonacci
- HDU 1568 Fibonacci(简单数论)
- HDU 1568 Fibonacci
- HDU 1568 Fibonacci
- HDU 1568 Fibonacci
- HDU 1568 Fibonacci
- HDU 1568 Fibonacci(数学 递推式)
- HDU 1568 Fibonacci
- hdu1568 Fibonacci
- hdu 1568 Fibonacci
- 数论(fabonacci数列) hdu-1568-Fibonacci
- HDU 1568 Fibonacci 公式 *
- HDU 1568 Fibonacci 【FIB通项公式+log10取前N为位数】
- HDU 1568 Fibonacci 公式求斐波那契数列
- hdu 1568 fibonacci
- hdu 1568 Fibonacci解题思路
- HDU 1568 Fibonacci
- 【HDU 1568】Fibonacci 数学公式 详解