![]() |
VOOZH | about |
Given a number N, the task is to check if the given number and all its digits are Fibonacci. If so, then the given number is a Full Fibonacci Number, else not.
Examples:
Input: 13
Output: Yes
Explanation: 13 and its digits 1 and 3 are all Fibonacci numbers
Input: 34
Output: No
Explanation: 4 is not a Fibonacci number.
Approach:
First check if all digits of N are Fibonacci or not. If so, similarly check if N is Fibonacci or not by the principle that a number is Fibonacci if and only if one or both of (5*N2 + 4) or (5*N2 – 4) is a perfect square.
Below code is the implementation of the above approach:
Yes
Time Complexity: O(logn)
Auxiliary Space: O(1)