2834 Fibonacci Numbers
time limit: 1 sspace limit: 128000 KBtitle level: Golden Gold SolvingView Run ResultsTitle Description
Description
Little X is a clever boy who remembers the first 1000 numbers in the Fibonacci series F (N). But because of academic pressure, he could not remember the position of each number in the series.
He now knows a number in the Fibonacci sequence F (x) modulo p after the value N (i.e. f (x) mod p=n) and x possible maximum m, if the retracement in the sequence of every number of modulo p, he would like to know that this number may appear in the first few. But the small x also has to do the homework, this question is handed over to you by the programming to solve.
Enter a description
Input Description
A row, a total of 3 integers, the first number is N, the second number is P, the third number is the maximum possible value of x m, and three numbers are separated by a space.
Output description
Output Description
An integer that satisfies the minimum I of the F (i) mod P = n and outputs-1 if it does not exist.
Sample input
Sample Input
3 7 5
Sample output
Sample Output
4
Data range and Tips
Data Size & Hint
For 20% of data, ensure 0
For 50% of data, ensure 0
For 70% of data, ensure 0
For 100% of the data, the 0
Category labels
Tags Click here to expand
Analysis :
Test instructions: Seek a Fibonacci number to satisfy the data range of F[i]%p==n (M is required f[i]) output I (he is in the position of the sequence)
Release code :
#include <iostream>#include<cstdio>#include<cstring>using namespacestd;intf[10110]={0,1,1},n,p,m;intMain () {scanf ("%d%d%d",&n,&p,&m); if(n==0|| n==1) {printf ("%d\n", F[n]);return 0;} for(intI=2; i<=m;i++) {F[i]= (f[i-1]%p+f[i-2]%p)%p;//Congruence and modulus arithmetic if(f[i]%p==n) {printf ("%d\n", i);return 0;} } printf ("-1\n"); return 0;}
2834 Fibonacci Numbers