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; }
相关文章推荐
- SQL Server获取自增列下一个Id
- 怎么判断两个cstring变量是否相等?
- 路由器开发相关知识总结 —— IEEE1588基础知识
- JACK编译器配置
- 深入浅出谱减法去噪
- 程序的机器级表示 (2)
- GCC的浅层理解
- Android之WebView与原生js之间的相互调用
- C语言背景颜色
- SQL Server Replication II
- 【树的重心】 POJ 1655 Balancing Act
- TestNg参数化测试之读取csv文件
- HDU2096 小明A+B
- 腾讯马化腾:云服务的安全问题是我最忧虑的(通过云,180多人能挣了10亿美金的利润)
- Andrid5.0新特性——SVG、VectorDrawable
- 自定义拖拽cell
- 图论专题总结
- [东莞市选2007]最难的问题_纪中1001_spfa
- Linux vmstat命令详解
- C语言中函数传递(实参 形参)