您的位置:首页 > 其它

FJ省队集训DAY4 T2

2016-07-06 20:37 309 查看




XXX



#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
typedef unsigned long long ll;
ll a,mod=1,L=1;
ll tr[4],b[4],tmp[4];
std::vector <ll> ans,ans2;
ll read(){
ll t=0,f=1;char ch=getchar();
while (ch<'0'||ch>'9'){if (ch=='-')f=-1;ch=getchar();}
while ('0'<=ch&&ch<='9'){t=t*10+ch-'0';ch=getchar();}
return t*f;
}
ll Mul(ll a,ll b){
if (mod<=1000000000)
return a*b%mod;
else
return b?((Mul(a,b>>16)<<16)+a*(b&65535))%mod:0;
}
void Mul(ll *a,ll *b) {
static ll c[4];
c[0]=(Mul(a[0],b[0])+Mul(a[1],b[2]))%mod;
c[1]=(Mul(a[0],b[1])+Mul(a[1],b[3]))%mod;
c[2]=(Mul(a[2],b[0])+Mul(a[3],b[2]))%mod;
c[3]=(Mul(a[2],b[1])+Mul(a[3],b[3]))%mod;
memcpy(a,c,sizeof c);
}
void init(ll *tr,ll L){
static ll tc[4];
tc[0]=0; tc[1]=1; tc[2]=1; tc[3]=1;
tr[0]=1; tr[1]=0; tr[2]=0; tr[3]=1;
for (;L;L>>=1,Mul(tc,tc))
if (L&1) Mul(tr,tc);
}
int main(){
cin>>a;ans.push_back(0);mod=1;L=1;
for (int p=1;p<=13;p++){
mod*=10;
init(tr,L);
init(b,0);
ll L2=0;
do{
for (int i=0;i<ans.size();i++){
init(tmp,ans[i]+L2);
if (tmp[2]==a%mod) ans2.push_back(ans[i]+L2);
}
L2+=L;
Mul(b,tr);
}while(b[0]!=1||b[1]!=0||b[2]!=0||b[3]!=1);
std::swap(ans,ans2);
ans2.clear();
L=L2;
}
if (ans.empty()) puts("-1");
std::cout<<ans[0]<<std::endl;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: