Exponential Fibonacci (Part 2)

Published by jota in

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.

Watch a quick demo on how Edabit works.