Math::NumSeq::PisanoPeriod -- cycle length of Fibonacci numbers mod i


 use Math::NumSeq::PisanoPeriod;
 my $seq = Math::NumSeq::PisanoPeriod->new;
 my ($i, $value) = $seq->next;


This is the length cycle of Fibonacci numbers modulo i.

    1, 3, 8, 6, 20, 24, 16, 12, 24, 60, 10, 24, 28, 48, 40, ...
    starting i=1

For example Fibonacci numbers modulo 4 repeat in a cycle of 6 numbers, so value=6.

   Fibonacci  0, 1, 1, 2, 3, 5, 8,13,21,34,55,89,144,...
   mod 4      0, 1, 1, 2, 3, 1, 0, 1, 1, 2, 3, 1, 0,...
              \--------------/  \--------------/  \---
            repeating cycle of 6

The Fibonaccis are determined by a pair F[i],F[i+1] and there can be at most i*i many different pairs mod i, so there's always a finite repeating period. Since the Fibonaccis can go backwards as F[i-1]=F[i+1]-F[i] the modulo sequence is purely periodic, so the initial 0,1 is always part of the cycle.


See "FUNCTIONS" in Math::NumSeq for behaviour common to all sequence classes.

$seq = Math::NumSeq::PisanoPeriod->new ()

Create and return a new sequence object.

Random Access

$value = $seq->ith($i)

Return the Pisano period of $i.


Math::NumSeq, Math::NumSeq::Fibonacci, Math::NumSeq::FibonacciWord



Copyright 2012, 2013, 2014, 2016, 2019, 2020 Kevin Ryde

Math-NumSeq is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.

Math-NumSeq is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with Math-NumSeq. If not, see <>.