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
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
Comments
Leave a comment