FJ省队集训DAY4 T2

时间:2023-12-21 18:12:26

FJ省队集训DAY4 T2

FJ省队集训DAY4 T2

XXX

FJ省队集训DAY4 T2

 #include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
typedef unsigned long long ll;
ll a,mod=,L=;
ll tr[],b[],tmp[];
std::vector <ll> ans,ans2;
ll read(){
ll t=,f=;char ch=getchar();
while (ch<''||ch>''){if (ch=='-')f=-;ch=getchar();}
while (''<=ch&&ch<=''){t=t*+ch-'';ch=getchar();}
return t*f;
}
ll Mul(ll a,ll b){
if (mod<=)
return a*b%mod;
else
return b?((Mul(a,b>>)<<)+a*(b&))%mod:;
}
void Mul(ll *a,ll *b) {
static ll c[];
c[]=(Mul(a[],b[])+Mul(a[],b[]))%mod;
c[]=(Mul(a[],b[])+Mul(a[],b[]))%mod;
c[]=(Mul(a[],b[])+Mul(a[],b[]))%mod;
c[]=(Mul(a[],b[])+Mul(a[],b[]))%mod;
memcpy(a,c,sizeof c);
}
void init(ll *tr,ll L){
static ll tc[];
tc[]=; tc[]=; tc[]=; tc[]=;
tr[]=; tr[]=; tr[]=; tr[]=;
for (;L;L>>=,Mul(tc,tc))
if (L&) Mul(tr,tc);
}
int main(){
cin>>a;ans.push_back();mod=;L=;
for (int p=;p<=;p++){
mod*=;
init(tr,L);
init(b,);
ll L2=;
do{
for (int i=;i<ans.size();i++){
init(tmp,ans[i]+L2);
if (tmp[]==a%mod) ans2.push_back(ans[i]+L2);
}
L2+=L;
Mul(b,tr);
}while(b[]!=||b[]!=||b[]!=||b[]!=);
std::swap(ans,ans2);
ans2.clear();
L=L2;
}
if (ans.empty()) puts("-1");
std::cout<<ans[]<<std::endl;
}