http://wikioi.com/problem/2834/
没什么好讲的,注意细节
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<iomanip>
using namespace std;
long long f[ 1005 ] = { 0 , 1 , 1 } ;
int main()
{
int n , p , m , i ;
scanf( "%d%d%d" , &n , &p , &m );
if( n == 0 || n == 1 )
printf( "%d\n" , f[ n ] ) ;
else
{
for( i = 2 ; i <= m ; ++i )
{
f[ i ] = ( f[ i - 1 ] % p + f[ i - 2 ] % p ) % p ;
if( f[ i ] % p == n )
{
printf( "%d\n" , i ) ;
break ;
}
}
}
if( i == m + 1 )
printf( "-1\n" ) ;
return 0 ;
}