zoukankan      html  css  js  c++  java
  • 第4章-12.求满足条件的斐波那契数 (30分)

    斐波那契数,亦称之为斐波那契数列,指的是这样一个数列:1、1、2、3、5、8、13、21、……,这个数列从第3项开始,每一项都等于前两项之和。求大于输入数的最小斐波那契数。

    输入格式:

    在一行输人一个正整数n(n>=10)。

    输出格式:

    在一行输出大于n的最小斐波那契数。

    输入样例:

    在这里给出一组输入。例如:

    10
    
     

    输出样例:

    在这里给出相应的输出。例如:

    13
    
     
     1 # 求满足条件的斐波那契数
     2 # Author: cnRick
     3 # Time  : 2020-3-29
     4 num = int(input())
     5 Fibonacci = [1,1]
     6 newestFib_index = 2
     7 while True:
     8     Fibonacci.append(Fibonacci[newestFib_index-1] + Fibonacci[newestFib_index-2])
     9     if Fibonacci[newestFib_index] > num:
    10         print(Fibonacci[newestFib_index])
    11         break
    12     else:
    13         newestFib_index += 1
  • 相关阅读:
    Learn Goroutine
    Redis eviction policies
    Hungarian Algorithm
    Prime and Factors
    HDU 2642 Stars
    236. Lowest Common Ancestor of a Binary Tree
    Leetcode 96. Unique Binary Search Trees
    Search in Rotated Sorted Array
    ID Generator
    概率问题
  • 原文地址:https://www.cnblogs.com/dreamcoding/p/12592462.html
Copyright © 2011-2022 走看看