This question is the true test of a person's perception of mathematics ah .....
See $ \ frac {b- \ sqrt d} {2} $ necessary to form a think this is one of a root of a quadratic equation, and then to the solution.
Think of this step, then do just fine, because we can be listed on a $ n $ is recursive, then matrix multiplication can be accelerated.
The code is not posted ....