Fibonacci modulo p | C ++ program to find minimal 0 Fibonacci for a prime number p ; Returns position of first Fibonacci number whose modulo p is 0. ; add previous two remainders and then take its modulo p . ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int findMinZero ( int p ) { int first = 1 , second = 1 , number = 2 , next = 1 ; while ( next ) { next = ( first + second ) % p ; first = second ; second = next ; number ++ ; } return number ; } int main ( ) { int p = 7 ; cout << " Minimal ▁ zero ▁ is : ▁ " << findMinZero ( p ) << endl ; return 0 ; }