Fibonacci modulo p | Java program to find minimal 0 Fibonacci for a prime number p ; Function that returns position of first Fibonacci number whose modulo p is 0 ; add previous two remainders and then take its modulo p . ; Driver program
import java . io . * ; class FibZero { static int findMinZero ( int p ) { int first = 1 , second = 1 , number = 2 , next = 1 ; while ( next > 0 ) { next = ( first + second ) % p ; first = second ; second = next ; number ++ ; } return number ; } public static void main ( String [ ] args ) { int p = 7 ; System . out . println ( " Minimal ▁ zero ▁ is ▁ " + findMinZero ( p ) ) ; } }