hdu 1568 Fibonacci
2016-07-29 17:59
381 查看
代码
#include<cstdio> #include<cstdlib> #include<cmath> const double constant_a = (1 + sqrt(5)) / 2; const double constant_b = (1 - sqrt(5)) / 2; const double constant_c = sqrt(5) / 5; int main(){ int n; while(~scanf("%d",&n)){ if(n==0){ printf("0\n"); continue; } int ans; if(n<=20) ans=(int)(constant_c * (pow(constant_a, n) - pow(constant_b, n))); else ans=(int)pow(10.0, 3.0 + fmod(-0.5*log10(5.0)+n*log10(constant_a), 1));; printf("%d\n",ans); } return 0; }
总结
最后一项小于0并且很小可以不用计算
相关文章推荐
- over partition by与group by 的区别
- 内置函数:hex、oct、bin
- Django1.8教程——从零开始搭建一个完整django博客(二)
- JavaWeb学习总结(三十五)——使用JDBC处理Oracle大数据
- Log4j使用手册
- error: LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: __cdecl QWidget::
- 机器学习面试问题7
- 反编译 jadx进行安卓反编译
- JFreeChart仪表图DialChartDemo1
- HDU 1875 畅通工程再续 (最小生成树)
- Oracle Partition By 的使用
- SQL集合运算参考及案例(一):列值分组累计求和
- 内置函数:chr_ord_bool
- # mysql CREATE TABLE IF NOT EXISTS metadata lock坑
- Java的方法
- Dungeon Master poj 2251
- Git简介
- ccnu_2016_summer_week1(2)_贪心
- 98.Which two statements are true regarding the usage of the SQL*Loader utility? (Choose two.)
- Mike and Feet(单调栈)