Answer to Question #283717 in Python for alk

Question #283717

Write a program to print the LARGEST ODD fibonaci number in a given range. If the number doesn't fall in the given range then print 0.



Example 1:

Given input

100

250

Expected output

233



Example 2:

Given input

4000

11000

Expected output

6765


1
Expert's answer
2021-12-30T07:13:43-0500
def oddFib(n):
    n = (3 * n + 1) // 2


    a = -1
    b = 1
    c = 0
    for i in range(1, n + 1):
        c = a + b
        a = b
        b = c


    return c


l = int(input())
r = int(input())
for i in range(r):
    if (oddFib(i) <= r and oddFib(i+1) > r):
        print(oddFib(i))
        break



Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS