hdu 6172(递推式
来源:互联网 发布:阿里云真实性核验单 编辑:程序博客网 时间:2024/05/18 02:59
传送门
Array Challenge
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 153428/153428 K (Java/Others)Total Submission(s): 143 Accepted Submission(s): 64
Problem Description
There’s an array that is generated by following rule.
h0=2,h1=3,h2=6,hn=4hn−1+17hn−2−12hn−3−16
And let us define two arraysbnandan as below.
bn=3hn+1hn+9hn+1hn−1+9h2n+27hnhn−1−18hn+1−126hn−81hn−1+192(n>0)
an=bn+4n
Now, you have to print⌊√(an)⌋ , n>1.
Your answer could be very large so print the answer modular 1000000007.
And let us define two arrays
Now, you have to print
Your answer could be very large so print the answer modular 1000000007.
Input
The first line of input contains T (1 <= T <= 1000) , the number of test cases.
Each test case contains one integer n (1 < n <=1015 ) in one line.
Each test case contains one integer n (1 < n <=
Output
For each test case print ⌊√(a_n )⌋ modular 1000000007.
Sample Input
3479
Sample Output
125532472513185773
Source
2017 Multi-University Training Contest - Team 10
Recommend
liuyiding | We have carefully selected several similar problems for you: 6181 6180 6179 6178 6177
草爆一切递推式。
#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#include <vector>#include <string>#include <map>#include <set>#include <cassert>using namespace std;#define rep(i,a,n) for (long long i=a;i<n;i++)#define per(i,a,n) for (long long i=n-1;i>=a;i--)#define pb push_back#define mp make_pair#define all(x) (x).begin(),(x).end()#define fi first#define se second#define SZ(x) ((long long)(x).size())typedef vector<long long> VI;typedef long long ll;typedef pair<long long,long long> PII;const ll mod=1e9+7;ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}// headlong long _,n;namespace linear_seq { const long long N=10010; ll res[N],base[N],_c[N],_md[N]; vector<long long> Md; void mul(ll *a,ll *b,long long k) { rep(i,0,k+k) _c[i]=0; rep(i,0,k) if (a[i]) rep(j,0,k) _c[i+j]=(_c[i+j]+a[i]*b[j])%mod; for (long long i=k+k-1;i>=k;i--) if (_c[i]) rep(j,0,SZ(Md)) _c[i-k+Md[j]]=(_c[i-k+Md[j]]-_c[i]*_md[Md[j]])%mod; rep(i,0,k) a[i]=_c[i]; } long long solve(ll n,VI a,VI b) { // a 系数 b 初值 b[n+1]=a[0]*b[n]+...// printf("%d\n",SZ(b)); ll ans=0,pnt=0; long long k=SZ(a); assert(SZ(a)==SZ(b)); rep(i,0,k) _md[k-1-i]=-a[i];_md[k]=1; Md.clear(); rep(i,0,k) if (_md[i]!=0) Md.push_back(i); rep(i,0,k) res[i]=base[i]=0; res[0]=1; while ((1ll<<pnt)<=n) pnt++; for (long long p=pnt;p>=0;p--) { mul(res,res,k); if ((n>>p)&1) { for (long long i=k-1;i>=0;i--) res[i+1]=res[i];res[0]=0; rep(j,0,SZ(Md)) res[Md[j]]=(res[Md[j]]-res[k]*_md[Md[j]])%mod; } } rep(i,0,k) ans=(ans+res[i]*b[i])%mod; if (ans<0) ans+=mod; return ans; } VI BM(VI s) { VI C(1,1),B(1,1); long long L=0,m=1,b=1; rep(n,0,SZ(s)) { ll d=0; rep(i,0,L+1) d=(d+(ll)C[i]*s[n-i])%mod; if (d==0) ++m; else if (2*L<=n) { VI T=C; ll c=mod-d*powmod(b,mod-2)%mod; while (SZ(C)<SZ(B)+m) C.pb(0); rep(i,0,SZ(B)) C[i+m]=(C[i+m]+c*B[i])%mod; L=n+1-L; B=T; b=d; m=1; } else { ll c=mod-d*powmod(b,mod-2)%mod; while (SZ(C)<SZ(B)+m) C.pb(0); rep(i,0,SZ(B)) C[i+m]=(C[i+m]+c*B[i])%mod; ++m; } } return C; } long long gao(VI a,ll n) { VI c=BM(a); c.erase(c.begin()); rep(i,0,SZ(c)) c[i]=(mod-c[i])%mod; return solve(n,c,VI(a.begin(),a.begin()+SZ(c))); }};int main() { for (scanf("%I64d",&_);_;_--) { scanf("%I64d",&n); printf("%I64d\n",linear_seq::gao(VI{31,197,1255,7997},n-2)); }}
阅读全文
1 0
- hdu 6172(递推式
- hdu 6172
- HDU 6172 Array Challenge 【线性递推式模板】
- HDU 6172-Array Challenge
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- PHP性能监控
- Kaldi学习之如何运行脚本
- Spring事务管理
- 2017 第十场多校训练 HDU 6181 Two Paths 次短路+Dijkstra
- tmp
- hdu 6172(递推式
- arm 数据比较基础知识
- 进度条2
- 乌班图16.04配置sdk
- anaconda安装完找不到.jupyter目录
- 用jquery做一个列表上下移动和置顶/低
- 欢迎使用CSDN-markdown编辑器
- java中web.xml的配置
- linux学习笔记一