We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Mathematics
- Fundamentals
- Is Fibo
- Discussions
Is Fibo
Is Fibo
+ 0 comments public static string isFibo(long n) { double squareTest = (5 * Math.Pow((double)n, 2)) + 4; double sqrt = Math.Sqrt(squareTest); if(sqrt % 1 == 0) return "IsFibo"; squareTest = (5 * Math.Pow((double)n, 2)) - 4; sqrt = Math.Sqrt(squareTest); if(sqrt % 1 == 0) return "IsFibo"; return "IsNotFibo"; }
+ 0 comments return "IsNotFibo" if (5*n**2+4)**0.5 % 1 and (5*n**2-4)**0.5 % 1 else "IsFibo"
+ 0 comments python3 using a generator
def fib(): a, b = 0, 1 while True: yield a a, b = b, a+b
def isFibo(n): # Write your code here f = fib() a = next(f) while a < n: a = next(f) if a == n: return 'IsFibo' else: return 'IsNotFibo'
+ 0 comments def isFibo(n): a, b = 0, 1 lst = [a, b] while b < n: a, b = b, a+b lst.append(b) return 'IsFibo' if n in lst else 'IsNotFibo'
+ 0 comments Python 3 Binet's formula
def IsFibo(n): return ('IsNotFibo', 'IsFibo')[any(filter(lambda x: x%1==0, (sqrt(5*n**2+4), sqrt(5*n**2-4))))]
Load more conversations
Sort 369 Discussions, By:
Please Login in order to post a comment