← Back to challenges

Exponential Fibonacci (Part 2)

PythonHardloopsmathnumbers

Instructions

Write a function that efficiently calculates the last digits of Fibonacci terms.

Examples

fibonacci(4, 2) ➞ 3

fibonacci(524288, 15) ➞ 122520212016581

fibonacci(524289, 18) ➞ 459462970016204514

Notes

The input will not be limited to powers of two.

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.