Fibonacci sequence Examples and C + + implementations

Source: Internet
Author: User

The Fibonacci sequence , also known as the Golden Section , refers to a sequence of numbers 0, 1, 1, 2, 3, 5, 8, 13, and 、...... In mathematics, the Fibonacci sequence is defined as follows : F (0) =0,f (1) =1,f (n) =f (n-1) +f (n-2) (n≥2,n∈n*) in modern physics, quasi-crystalline structure, chemistry and other fields, the Fibonacci sequence has a direct application, for this reason, From 1963, the American Mathematical Council published a mathematical magazine in the name of the Fibonacci series Quarterly, devoted to the research.

Fibonacci numbers refer to such a sequence of 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233,377,610,987,1597,2584,4181,6765,10946,17711,28657,46368
in particular, the No. 0 item is 0, and the 1th item is the first 1.

Rabbit Reproductive ProblemsThe Fibonacci sequence is also known as the "rabbit sequence" because of the example of the breeding of the rabbit by the mathematician Leonardo's Fibonacci. In general, after two months of birth, rabbits have the ability to reproduce, a pair of rabbits can produce a pair of rabbits each month. If all the rabbits are not dead, how many pairs of rabbits can be bred in a year? We may as well as the new born a pair of small rabbits analysis: The first month the small rabbit does not reproduce the ability, so still a pair of two months later, gave birth to a pair of small rabbits a total of two to three months later, the old rabbit again gave birth to a pair, because the rabbit has not yet reproductive ability, so altogether is three pairs---
After number of months 0 1 2 3 4 5 6 7 8 9 10 11 12
The logarithm of a young boy 1 0 1 1 2 3 5 8 13 21st 34 55 89
Into the rabbit logarithm 0 1 1 2 3 5 8 13 21st 34 55 89 144
Total logarithm 1 1 2 3 5 8 13 21st 34 55 89 144 233
The logarithm of a young child = the logarithm of a rabbit in the previous month = the logarithm of a rabbit in the previous month + the logarithm of the number of the first month of the Moon = the logarithm of a rabbit logarithm + this month the number of pups can be seen that the logarithm of the young, into the rabbit logarithm, the overall logarithm of a sequence. This series is concerned with the very obvious characteristics, that is: the sum of the preceding two adjacent, constitute the latter. The number of months is N, then there is F (0) =1;f (1) =1;f (n) =f (n-1) +f (n-2);Gold Divisionas the number of entries increases, the ratio of the previous item to the latter becomes more and more approximate.Gold Divisionthe value of 0.6180339887: ... ..
See 4Yang Hui TriangleThe Yang Hui triangle is left-aligned, arranged, and the number of the same diagonal line is added together, that is, a series 1, 1, 2, 3, 5, 8 、...... The formula is expressed as follows: F⑴=c (0,0) = 1. F⑵=c (1,0) = 1. F⑶=c (2,0) +c (=1+1=2). F⑷=c (3,0) +c (2,1) =1+2=3. F⑸=c (4,0) +c (3,1) +c (2,2) =1+3+1=5. F⑹=c (5,0) +c (4,1) +c (3,2) =1+4+3=8. F⑺=c (6,0) +c (5,1) +c (4,2) +c (3,3) =1+5+6+1=13. ...... F (n) =c (n-1,0) +c (n-2,1) +...+c (n-1-m,m) (m<=n-1-m) prime quality Fibonacci numbers and prime generation each of the 3 consecutive numbers and only one is divisible by 2, each 4 consecutive numbers and only one is divisible by 3, Every 5 consecutive numbers and only one is divisible by 5, each of the 6 consecutive numbers has and only one is divisible by 8, each of the 7 consecutive numbers and only one is divisible by 13, each 8 consecutive numbers and only one is divisible by 21, each 9 consecutive numbers and only one is divisible by 34, .... We see that 5th, 7, 11, 13, 17, 23 bits are prime numbers: 5,13,89,233,1597,28657 (19th place not)
Digital Puzzlesthree border of trianglesThe system theorem and the Fibonacci sequence of a link: the existing length of 144cm of iron wire, to cut into N small segment (n>2), the length of each segment is not less than 1cm, if any of the three small segments can not be spelled into a triangle, then the maximum value of n is how much? Analysis: As the necessary and sufficient conditions for the formation of a triangle is any of the two sides and greater than the third side, so does not constitute a triangle condition is any two sides and no more than the maximum edge. The smallest wire cut is 1, so can put 2 1, the third segment is 2 (in order to make the largest, so that the remaining wire as long as possible, so that each line is always the first adjacent 2 segments of the sum), in order: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, the sum of the above is 143, The difference is 1 from 144, so the last segment can be taken as 56, when n reaches the maximum of 10. We see that "the length of each paragraph is not less than 1" This condition plays a role in controlling the global, it is this minimum number 1 produces the Fibonacci sequence, if the 1 is replaced by other numbers, the recurrence relationship is retained, but the sequence disappears. Here, there is a connection between the triangular relationship theorem and the Fibonacci sequence. In this question, 144>143, this 143 is the first n of the Fibonacci sequence and, we add 144 out of 143 to the last number, and if added to other numbers, there are 3 segments that can form triangles. The Fibonacci sequence in the film and television works is well known in Europe and the United States, so in the film this popular art also often appear, such as in Rage's "Da Vinci Code" it as an important symbol and plot clues appear, in the "Magic Toy City" in the shopkeeper job fair timing casually asked questions. This series can be seen as popular as the Golden segment. But despite being called, most people recite the first few numbers and do not understand the study in depth. In the TV series also appeared Fibonacci series, such as: VCDs "The god of the test" the fifth, Yi-heir to do the national simulation test of the last maths problem ~ in the fox hit American drama "Fringe" is a lot of citations, even as the whole drama propaganda poster one of the design elements.permutation combinationsOne or one evenly-spaced coins were thrown 10 times, how many of the possible cases of discontinuous positive? The answer is 144 kinds.

Using the standard Fibonacci sequence (0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144), the answer is F (10+2).an even coin is thrown n times, and there may be an F (n+2) in the case of a discontinuous positive.

second, there is a staircase has 10 steps, the provisions of each step can only cross one or two levels, to ascend the 10th level of the steps there are several different ways to go?

This is a Fibonacci sequence: there is a way to ascend the first step, there are two ways to ascend the two-step ladder, three steps to ascend, three kinds of boarding methods, and a four-step ladder, five kinds of boarding law ... 1,2,3,5,8,13 ... So, on board level 10, there are 89 ways to go. This is not a standard Fibonacci sequence, initialized with F (0) =0,f (1) =1,f (2) =2. There is a problem with Leetcode:You is climbing a stair case. It takesNsteps to reach the top.

Each time you can either climb 1 or 2 steps. In what many distinct ways can you climb to the top?

The following can be implemented recursively:

int stairs_climbing1 (int n) {if (n==0| | n==1| | n==2) return N;return stairs_climbing1 (n-1) +stairs_climbing1 (n-2);}
But this method, every time f (n) is calculated from F (0) to F (n-1) and F (n-2) of the process will be repeated once, the computational time is very complex, unable to complete the work within the specified time. An improved algorithm that records the value of F (0) ~f (n), as follows:

int stairs_climbing (int n) {if (n==0| | n==1| | n==2) return N;vector<int >mem (n+1); mem[0]=0;mem[1]=1;mem[2]=2;int res;for (int i=3;i<n+1;i++) {mem[i]=mem[ I-1]+mem[i-2];} return mem[n];}

Extension as can be seen from the above example, when the initial value is different, F (n) =f (n-1) +f (n-2) may have a different result.

Fibonacci-Lucas SeriesLucas Series 1, 3, 4, 7, 11, 18 ..., also have the same nature as the Fibonacci sequence. (We can call it Fibonacci-Lucas recursion: Starting with the third item, each item is equal to the first two and f (n) = f (n-1) + f (n-2). Pell sequence 1,2,5,12,29, ..., there are also |2*2-1*5|=|5*5-2*12|=...=1 (this characteristic value of such a series is called the Tick feature). The recursive rule for the Pell sequence Pn: p1=1,p2=2,pn=p (n-2) +2p (n-1). Generalized Fibonacci SequenceBy analogy to all the general rules for exporting the third item according to the first two items: F (n) = f (n-1) * p + f (n-2) * Q, called the generalized Fibonacci sequence. When P=1,q=1, we get the Fibonacci-Lucas sequence. When p=1,q=2, we get the Pell-hook chord number (the set of series related to the right triangle with an integer of the side length). When P=2,q=-1, we get arithmetic progression. Where f1=1,f2=2, we get the natural sequence 1,2,3,4 .... The characteristic of the natural sequence is that the difference between the square of each number and the product of two numbers before and after is 1 (the difference of arithmetic progression is called the natural feature). The generalized-Fibonacci sequence p=±1 with similar gold characteristics, tick-off characteristics and natural features. When f1=1,f2=2,p=2,q=0, we get geometric series 1,2,4,8,16 ... This article refers to:
Http://baike.baidu.com/link?url=uYAPJgZmzQDU8wuN0H4QjB1nBUqRPtNeNz5yAzDGpcUWhBqT6KNGvvC-9iroF6TxScwngt_jM4-6XGQDppiKEK


We may as well as the new born a pair of small rabbits analysis: The first month the small rabbit does not reproduce the ability, so still a pair of two months later, gave birth to a pair of small rabbits a total of two to three months later, the old rabbit again gave birth to a pair, because the rabbit has not yet reproductive ability, so altogether is three pairs---
After number of months 0 1 2 3 4 5 6 7 8 9 10 11 12
The logarithm of a young boy 1 0 1 1 2 3 5 8 13 21st 34 55 89
Into the rabbit logarithm 0 1 1 2 3 5 8 13 21st 34 55 89 144
Total logarithm 1 1 2 3 5 8 13 21st 34 55 89 144 233
The logarithm of a young child = the logarithm of a rabbit in the previous month = the logarithm of a rabbit in the previous month + the logarithm of the number of the first month of the Moon = the logarithm of a rabbit logarithm + this month the number of pups can be seen that the logarithm of the young, into the rabbit logarithm, the overall logarithm of a sequence. This series is concerned with the very obvious characteristics, that is: the sum of the preceding two adjacent, constitute the latter. The number of months is N, then there is F (0) =1;f (1) =1;f (n) =f (n-1) +f (n-2);Gold DivisionAs the number of entries increases, the ratio of the previous item to the latter is more and more close to the value of golden 0.6180339887. ...
See 4Yang Hui Triangle

Fibonacci sequence Examples and C + + implementations

Related Article

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.