Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use Fibonacci numbers

Shulou Source: shulou.com Published: 2022-06-03 07:26:29 11月15日 Update

This article mainly explains "how to use Fibonacci numbers". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use Fibonacci numbers".

Problem description

Fibonacci numbers, also known as Fibonacci series, refer to such a series: 1, 1, 2, 3, 5, 8, 13, 21, …... This series starts with the third term, and each term is equal to the sum of the first two terms. Find the minimum Fibonacci number that is greater than the input number.

Enter: enter a positive integer n (n > = 10) on one line.

Output: output the minimum Fibonacci number greater than n on one line.

Input sample: 10

Sample output: 13

Solution

The generator, the python language, is used first. Generator definition: a function that uses yield is called a generator. In the process of calling the generator to run, the function pauses and saves all the current running information each time it encounters yield, returns the value of yield, and continues to run from the current location the next time the next () method is executed. Use the generator to get the Fibonacci series, and then display the series as a list. Compare the numbers in the series with the integers entered, filter out the numbers that meet the criteria, and then create a new list to put the numbers that meet the criteria. Finally, print out the first element of the new list, that is, the minimum Fibonacci number that meets the criteria!

Thank you for your reading. the above is the content of "how to use Fibonacci numbers". After the study of this article, I believe you have a deeper understanding of how to use Fibonacci numbers, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Series generator generation input minimum condition learning output run line content function integer problem sum location information element form idea Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info NVidia Shulou Information MySQL Microsoft