当前位置:网站首页>HDU3117 Fibonacci Numbers【数学】
HDU3117 Fibonacci Numbers【数学】
2022-07-27 13:49:00 【51CTO】
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=3117
题目大意:
给你一个整数N(0 <= N <= 10^8),求斐波那契数列第N项F[N]的前四位数字和末尾四位数字。
思路:
斐波那契数列是一个很大的数,直接暴力枚举显然不科学。先考虑末尾4位是否有循环节,写个
程序发现循环节是15000,直接用数组存储前15000的斐波那契数列的末尾4位。至于斐波那契
数列的前4位。通过计算得出N >= 40之后,F[N]就大于8位数了。对于N < 40的部分可以直接
输出结果,对于N >= 40的部分,考虑公式 F[N] =(1/√5) * ( ((1+√5)/2)^n - ((1-√5)/2)^n )。
设F[N]可表示为t * 10^k(t为一个小数),那么对F[N] = t * 10^k两边分别取对数log10,得到:
log10(F[N]) = log10(t) + k 。log10(t) = log10(F[N]) - k,因为t肯定是小于10的小数,所以,
log10(t) < 1,而且k为整数,那么log10(t)的值就是log10(F[N])去掉整数部分的小数部分。
用pow(10.0,log10(t))求出t。将t*1000取整数部分就得到了F[N]的前4位。
还有一点,求F[N] = (1/√5) * ( ((1+√5)/2)^n - ((1-√5)/2)^n )的时候,因为N>=40的时候,
((1-√5)/2)^n已经是一个非常小的小数(小数点后10位左右),所以可以直接忽略。这样子,
F[N] ≈ (1/√5) * ((1+√5)/2)^n。log10(F[N])化简为:1/sqrt(5.0) + N*log10(1+(sqrt(5.0))/2.0)。
AC代码:
边栏推荐
- Rtl8762dk environment construction (I)
- How to solve cache avalanche, breakdown and penetration problems
- codeforces 1708E - DFS Trees
- Docker实践经验:Docker 上部署 mysql8 主从复制
- The difference between [x for X in list_a if not np.isnan (x)] and [x if not np.isnan (x) else none for X in list_a]
- Navicate报错access violation at address 00000000
- Stock trading 4
- MySQL save data prompt: out of range value for column error
- log4j2 jdbc appender
- 汉字风格迁移篇---对抗性区分域适应(L1)Adversarial Discriminative Domain Adaptation
猜你喜欢

Architecture - the sublimation of MVC

文献翻译__基于自适应全变差L1正则化的椒盐图像去噪

SkyWalking分布式系统应用程序性能监控工具-中

What you want most is the most comprehensive summary of C language knowledge. Don't hurry to learn

在Oracle VirtualBox中导入Kali Linux官方制作的虚拟机

如果我们是那晚负责修复 B 站崩了的开发人员

STM32 - capacitive touch button experiment

大家最想要的,最全的C语言知识点总结,还不赶紧学习

机场云商sign解析

codeforces 1708E - DFS Trees
随机推荐
telnet远程登录aaa模式详解【华为eNSP】
Who can't capture packets these days? Wireshark packet capture and common protocol analysis are for you!
Carla notes (04) - client and world (create client, connect world, batch object, set weather, set lights, world snapshots)
How to solve cache avalanche, breakdown and penetration problems
Hard deduction SQL statement exercises, wrong question records
次小生成树【模板】
TXT把换行 替换为空格或者取消换行
Stock trading 4
What you want most is the most comprehensive summary of C language knowledge. Don't hurry to learn
codeforces 1708E - DFS Trees
watch VS watchEffect
视觉系统设计实例(halcon-winform)-9.文字显示
Is there a regular and safe account opening platform for gold speculation
初学者入门:使用WordPress搭建一个专属自己的博客
HDU4565 So Easy! [matrix multiplication] [derivation]
np. Usage and difference of range() and range()
【论文精读】Grounded Language-Image Pre-training(GLIP)
JS 疫情宅在家,学习不能停,七千字长文助你彻底弄懂原型与原型链
mysql保存数据提示:Out of range value for column错误
< C> C language hash table usage