当前位置:网站首页>Hdu3117 Fibonacci numbers [mathematics]
Hdu3117 Fibonacci numbers [mathematics]
2022-07-27 14:56:00 【51CTO】
Topic link :
http://acm.hdu.edu.cn/showproblem.php?pid=3117
The main idea of the topic :
Give you an integer N(0 <= N <= 10^8), Find Fibonacci number number number number number number N term F[N] The first four digits and the last four digits of .
Ideas :
Fibonacci sequence is a big number , Direct violence enumeration is obviously unscientific . Consider the end first 4 Whether the bit has a cyclic section , Write a
The program found that the loop section is 15000, Directly use the array to store the front 15000 At the end of the Fibonacci sequence of 4 position . As for Fibonacci
Before the sequence 4 position . It is calculated that N >= 40 after ,F[N] Greater than 8 Number of digits . about N < 40 The part of can be directly
Output results , about N >= 40 Part of , Consider the formula F[N] =(1/√5) * ( ((1+√5)/2)^n - ((1-√5)/2)^n ).
set up F[N] Can be expressed as t * 10^k(t Is a decimal ), So right. F[N] = t * 10^k Take logarithms on both sides log10, obtain :
log10(F[N]) = log10(t) + k .log10(t) = log10(F[N]) - k, because t It must be less than 10 Decimals of , therefore ,
log10(t) < 1, and k Integers , that log10(t) The value is log10(F[N]) Remove the decimal part of the integer part .
use pow(10.0,log10(t)) Find out t. take t*1000 Take the integer part and you get F[N] Before 4 position .
And a little bit more , seek F[N] = (1/√5) * ( ((1+√5)/2)^n - ((1-√5)/2)^n ) When , because N>=40 When ,
((1-√5)/2)^n It is already a very small decimal ( After the decimal point 10 Bit left and right ), So you can directly ignore . It looks like ,
F[N] ≈ (1/√5) * ((1+√5)/2)^n.log10(F[N]) Simplify :1/sqrt(5.0) + N*log10(1+(sqrt(5.0))/2.0).
AC Code :
边栏推荐
猜你喜欢

Interprocess communication

Unity3d learning note 10 - texture array

终于有人把面试必考的动态规划、链表、二叉树、字符串全部撸完了

Slam overview Reading Note 7: visual and visual intangible slam: state of the art, classification, and empirical 2021

FPGA timing constraint sharing 04_ Output delay constraint

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

DVWA全级别通关教程
![[popular science] the difference and connection between accuracy and resolution](/img/12/efcce1f6b8801d8d8b08b79818632c.png)
[popular science] the difference and connection between accuracy and resolution

Graphic SQL of giant image

视觉系统设计实例(halcon-winform)-9.文字显示
随机推荐
Nokia's patent business was hit for the first time, and Chinese enterprises are not so easy to knead
线程知识总结
DXGI acquisition process
CPU、GPU、NPU的区别
股票买卖4
Summary of basic knowledge of C language
User question understanding and answer content organization for epidemic disease Science Popularization
NEFU117 素数个数的位数【素数定理】
log4j2 jdbc appender
Graphic SQL of giant image
Simple encapsulation steps of request data request of uniapp
Understand the evolution of redis architecture in one article
一篇文章看懂JS执行上下文
What if win11 wallpaper turns black? The solution of win11 wallpaper blackening
NEFU119 组合素数【算术基本定理】
Hdu1422 revisits the world cup [DP]
FPGA时序约束分享04_output delay 约束
How to do well in enterprise system vulnerability assessment
C语言基础知识梳理总结
正向代理与反向代理