#fibonacci-number #fibonacci #linear #recurrence #performance

fast-fibonacci

Quickly find nth fibonacci number with modulo. Supports u64 and BigUint.

4 releases

0.2.0 Oct 20, 2020
0.1.2 Oct 19, 2020
0.1.1 Oct 19, 2020
0.1.0 Oct 19, 2020

#20 in #fibonacci-number

Download history 10/week @ 2024-11-14 4/week @ 2024-11-21 3/week @ 2024-11-28 10/week @ 2024-12-05 13/week @ 2024-12-12 6/week @ 2024-12-19 1/week @ 2025-01-02 7/week @ 2025-01-09 1/week @ 2025-01-16 3/week @ 2025-01-23 11/week @ 2025-01-30 237/week @ 2025-02-06 244/week @ 2025-02-13 167/week @ 2025-02-20 190/week @ 2025-02-27

844 downloads per month

GPL-3.0-or-later

16KB
168 lines

fast-fibonacci Crate Build Status

Quickly find nth fibonacci number, with modulo.

fn fib_with_mod(n: u64, modulo: u64) -> u64

Uses linear recurrence to find nth fibonacci number with modulo. O(log(n))

fn bigfib_with_mod(n: &BigUint, modulo: &BigUint) -> BigUint

BigUint version of fib_with_mod. Uses linear recurrence to find nth fibonacci number with modulo. O(log(n))


lib.rs:

fast-fibonacci

fast-fibonacci uses linear recurrence to quickly find fib(n, mod) in O(log(n)) time.

Adapted from http://fusharblog.com/solving-linear-recurrence-for-programming-contest/

Dependencies

~2MB
~37K SLoC