[I will forget it when I arrive at the competition anyway] entry to the Fibonacci series and an example

Source: Internet
Author: User

For me to wait for a mathematical color pen, right should broaden the knowledge of number theory .. It is estimated that nothing will come to mind during the competition .... Orz

1. Fibonacci series.

This series is well-known and came out when Fibonacci was studying rabbit production patterns. On the surface, F (0) = 0, F (1) = 1, F (2) = f (0) + F (1 ).... F (n) = f (n-1) + f (n-2), with the brain is still very good to push, but the computer with recursive words is slightly self-defeating, by one hundred, Stack Overflow collapsed.

So a great mathematician got a general formula. The general formula of All Integer series was actually composed of irrational numbers multiplied ??! It is also the famous golden split number.

This formula can be used to solve a lot of self-defeating problems, such as this (HDU 1568): Click to open the link

Is the first four digits of the FIB number that must be close to any item .. Normally, this is definitely not possible.

Take the logarithm on both sides: (The following fonts are reprinted)

Log10 (an) =-0.5 * log10 (5.0) + (double) n) * log (f)/log (10.0) + log10 (1-(1-√ 5)/(1 + √ 5) ^ N)

F = (SQRT (5.0) + 1.0)/2.0;

Because log10 (1-(1-√ 5)/(1 + √ 5) ^ N) approaches 0
Therefore, you can write log10 (an) =-0.5 * log10 (5.0) + (double) n) * log (f)/log (10.0 );
Finally, the fractional part is taken. The decimal part of the result is bit, and then retrieved using POW (10.0, bit .. If it is less than one thousand, just take the ride.

The reference discuss is not clear, and the code is simplified to get clear:

# Include <iostream> # include <cmath> using namespace STD; const double F = (SQRT (5.0) + 1.0)/2.0; int tab [100]; int lowbiter; void lowfib () {tab [1] = 1; tab [0] = 0; For (INT I = 2; I <100; I ++) {tab [I] = tab [I-1] + TAB [I-2]; // smaller digits are defined for solving if (Tab [I]> 10000) {lowbiter = I; break ;}} double fib (int n) {return (-0.5 * log (5.0)/log (10.0) + (double) n) * log (f) /log (10.0); // use the generic formula to obtain the logarithm of Multiple Digits.} int main () {int N; lowfib (); While (CIN> N) {If (n <lowbiter) {cout <tab [N] <Endl;} else {double bit = fib (n); double res = bit-floor (BIT ); res = POW (10.0, Res); While (RES <1000) RES * = 10; cout <(INT) RES <Endl ;}} return 0 ;}

Finally, the solution to the large fib number is basically based on the general term formula and the search rule. Of course, this idea may be basically unexpected during the competition ..

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.