zoukankan      html  css  js  c++  java
  • FJ省队集训DAY4 T2

    XXX

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<cmath>
     4 #include<cstring>
     5 #include<algorithm>
     6 #include<vector>
     7 using namespace std;
     8 typedef unsigned long long ll;
     9 ll a,mod=1,L=1;
    10 ll tr[4],b[4],tmp[4];
    11 std::vector <ll> ans,ans2;
    12 ll read(){
    13     ll t=0,f=1;char ch=getchar();
    14     while (ch<'0'||ch>'9'){if (ch=='-')f=-1;ch=getchar();}
    15     while ('0'<=ch&&ch<='9'){t=t*10+ch-'0';ch=getchar();}
    16     return t*f;
    17 }
    18 ll Mul(ll a,ll b){
    19     if (mod<=1000000000)
    20      return a*b%mod;
    21     else 
    22      return b?((Mul(a,b>>16)<<16)+a*(b&65535))%mod:0; 
    23 }
    24 void Mul(ll *a,ll *b) {
    25     static ll c[4];
    26     c[0]=(Mul(a[0],b[0])+Mul(a[1],b[2]))%mod;
    27     c[1]=(Mul(a[0],b[1])+Mul(a[1],b[3]))%mod;
    28     c[2]=(Mul(a[2],b[0])+Mul(a[3],b[2]))%mod;
    29     c[3]=(Mul(a[2],b[1])+Mul(a[3],b[3]))%mod;
    30     memcpy(a,c,sizeof c);
    31 }
    32 void init(ll *tr,ll L){
    33     static ll tc[4];
    34     tc[0]=0; tc[1]=1; tc[2]=1; tc[3]=1;
    35     tr[0]=1; tr[1]=0; tr[2]=0; tr[3]=1;
    36     for (;L;L>>=1,Mul(tc,tc))
    37         if (L&1) Mul(tr,tc);
    38 }
    39 int main(){
    40     cin>>a;ans.push_back(0);mod=1;L=1;
    41     for (int p=1;p<=13;p++){
    42         mod*=10;
    43         init(tr,L);
    44         init(b,0);
    45         ll L2=0;
    46         do{
    47          for (int i=0;i<ans.size();i++){
    48                 init(tmp,ans[i]+L2);
    49                 if (tmp[2]==a%mod) ans2.push_back(ans[i]+L2);
    50          }
    51          L2+=L;
    52          Mul(b,tr);
    53         }while(b[0]!=1||b[1]!=0||b[2]!=0||b[3]!=1);
    54         std::swap(ans,ans2);
    55         ans2.clear();
    56         L=L2;
    57     }
    58     if (ans.empty()) puts("-1");
    59     std::cout<<ans[0]<<std::endl;
    60 }
  • 相关阅读:
    16-异常
    Linux 常用命令
    项目依赖子项目的类
    Struts2
    博客园【上吊猫】
    LayUI【基本使用】
    idea中隐藏.iml文件
    Session 使用
    博客园右下角看板娘特效,多种样式可选
    枚举
  • 原文地址:https://www.cnblogs.com/qzqzgfy/p/5648032.html
Copyright © 2011-2022 走看看