You can use the matrix exponentiation method (linear recurrence method).
You can find detailed explanation and procedure in this or this blog. Run time is O(log n).
I don’t think there is a better way of doing this.
More Related Contents:
- Test if a number is fibonacci
- An inverse Fibonacci algorithm?
- Custom Weighted Scale [closed]
- Sum a number with divisors to get another number
- How to create the most compact mapping n → isprime(n) up to a limit N?
- Mapping two integers to one, in a unique and deterministic way
- Least common multiple for 3 or more numbers
- Select k random elements from a list whose elements have weights
- Is it possible to express “t” variable from Cubic Bezier Curve equation?
- Choosing n numbers with fixed sum
- Need help in mod 1000000007 questions
- What is the fastest integer factorization algorithm?
- Check if one integer is an integer power of another
- Modulus power of big numbers
- Puzzle: Find largest rectangle (maximal rectangle problem)
- How can I calculate the age of a person in year, month, days?
- Why is the complexity of computing the Fibonacci series 2^n and not n^2?
- finding a^b^c^… mod m
- Determining if two line segments intersect? [duplicate]
- Fastest algorithm for circle shift N sized array for M position
- How do you find a point at a given perpendicular distance from a line?
- How to find distance from the latitude and longitude of two locations?
- Reverse complex 2D lookup table
- How do I determine whether my calculation of pi is accurate?
- JavaScript: Calculate the nth root of a number
- Given Prime Number N, Compute the Next Prime?
- Calculating phi(k) for 1
- Can a Fibonacci function be written to execute in O(1) time?
- Optimized low-accuracy approximation to `rootn(x, n)`
- How can I perform Collision Detection on rotated rectangles? [closed]