Metaphysical questions ...
First, if $ f_ {i} \ equiv a $ $ mod $ $ 10 ^ {y} $, then there must be $ f_ {i} \ equiv a $ $ mod $ $ 10 ^ {y-1} $
Accordingly, we can find only meet $ f_ {i} \ equiv a $ $ mod $ $ 10 ^ {y-1} $ item, and then upward to test
But this term is endless ah
Fibonacci numbers listed in the lower mold section circulation sense, and $ 10 ^ {y} $ loop segment length must be an integer multiple of $ 10 ^ {y-1} $ cycle length section
We round-robin section length enumerate just fine
Code:
#include <cstdio> #include <cmath> #include <cstring> #include <cstdlib> #include <iostream> #include <algorithm> #include <queue> #include <stack> #define ll long long using namespace std; ll mode,len; ll pow_add(ll x,ll y) { ll ret=0; while(y) { if(y&1)ret=(ret+x)%mode; x=(x+x)%mode,y>>=1; } return ret; } struct MAT { ll a[2][2]; friend MAT operator * (MAT x,MAT y) { MAT ret; memset(ret.a,0,sizeof(ret.a)); for(int i=0;i<=1;i++)for(int j=0;j<=1;j++)for(int k=0;k<=1;k++)ret.a[i][j]=(ret.a[i][j]+pow_add(x.a[i][k],y.a[k][j]))%mode; return ret; } MAT pow_mul(MAT x,ll y) { MAT ret; ret.a[0][0]=ret.a[1][1]=1; ret.a[1][0]=ret.a[0][1]=0; while(y) { if(y&1)ret=ret*x; x=x*x,y>>=1; } return ret; } }f,g,ori,t; ll q; vector <ll> ans,tempans; int main() { freopen("words.in","r",stdin); freopen("words.out","w",stdout); scanf("%lld",&q); mode=len=1; ans.push_back(0); ori.a[0][0]=ori.a[1][0]=ori.a[0][1]=1; for(int i=1;i<=13;i++) { mode*=10; f=f.pow_mul(ori,0),g=g.pow_mul(ori,len); ll templen=0; do{ for(int j=0;j<ans.size();j++) { if(t.pow_mul(ori,ans[j]+templen).a[0][1]==q%mode)tempans.push_back(ans[j]+templen); } f=f*g,templen+=len; }while(f.a[0][0]!=1||f.a[1][0]!=0||f.a[0][1]!=0|f.a[1][1]!=1); ans=tempans,tempans.clear(),len=templen; } if(ans.empty())printf("-1\n"); else printf("%lld\n",ans[0]); return 0; }