DEV Community

Rajrishi Vishwakarma
Rajrishi Vishwakarma

Posted on

1

Finding Nth Fibonacci number in constant time.

The below code uses Binet's Algorithm to find the nth Fibonacci number.

int nthFibonacci(int n){
    double phi= double(1+sqrt(5))/2; 
    return round(pow(phi,n)/sqrt(5));
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

AI Agent image

How to Build an AI Agent with Semantic Kernel (and More!)

Join Developer Advocate Luce Carter for a hands-on tutorial on building an AI-powered dinner recommendation agent. Discover how to integrate Microsoft Semantic Kernel, MongoDB Atlas, C#, and OpenAI for ingredient checks and smart restaurant suggestions.

Watch the video 📺

👋 Kindness is contagious

Explore this insightful post in the vibrant DEV Community. Developers from all walks of life are invited to contribute and elevate our shared know-how.

A simple "thank you" could lift spirits—leave your kudos in the comments!

On DEV, passing on wisdom paves our way and unites us. Enjoyed this piece? A brief note of thanks to the writer goes a long way.

Okay