HDU 6172-Array Challenge
来源:互联网 发布:淘宝我的购物车打不开 编辑:程序博客网 时间:2024/06/16 07:32
Array Challenge
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 153428/153428 K (Java/Others)
Total Submission(s): 97 Accepted Submission(s): 38Problem 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 arrays bnandan 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.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.Output
For each test case print⌊√(an)⌋ modular 1000000007.Sample Input
3
4
7
9Sample Output
1255
324725
13185773Source
2017 Multi-University Training Contest - Team 10
题意:
求
一波打表后可以发现答案和
事实上进一步地有
- AC代码
#include <bits/stdc++.h>using namespace std;#define mem(s,v) memset(s,v,sizeof(s))typedef long long ll;const double PI = acos(-1);const ll MOD = 1000000007;const int inf = 0x3f3f3f3f;const ll INF = 0x3f3f3f3f3f3f3f3f;const int N = 2;//方阵维数struct Mat{ ll mat[N][N];}E;//初始化单位矩阵Mat init(){ Mat E; for(int i = 0; i < N; i++){ for(int j = 0; j < N; j++){ if(i == j) E.mat[i][i] = 1; else E.mat[i][j] = 0; } } return E;}//重载乘法Mat operator *(Mat a,Mat b){ Mat c; memset(c.mat,0,sizeof(Mat)); for(int i = 0; i < N; i++){ for(int j = 0; j < N; j++){ for(int k = 0; k < N; k++){ if(a.mat[i][k] && b.mat[k][j]){ c.mat[i][j] += a.mat[i][k] * b.mat[k][j]; c.mat[i][j] %= MOD; } } } } return c;}//重载加法Mat operator +(Mat a,Mat b){ Mat c; memset(c.mat,0,sizeof(Mat)); for(int i = 0; i < N; i++){ for(int j = 0; j < N; j++){ c.mat[i][j] = a.mat[i][j] + b.mat[i][j]; } } return c;}//矩阵快速幂Mat operator ^(Mat A,ll x){ Mat c; c = init(); for(; x ; x >>= 1){ if(x&1){ c = c*A; } A = A*A; } return c;}ll get(ll x){ if(x == 2)return 31; if(x == 3)return 197; Mat EE; EE.mat[0][0] = 0; EE.mat[0][1] = 1; EE.mat[1][0] = -4; EE.mat[1][1] = 7; ll beg[2] = {31,197}; EE = EE^(x - 3); ll s1 = EE.mat[0][0]*beg[0] + EE.mat[0][1]*beg[1]; ll s2 = EE.mat[1][0]*beg[0] + EE.mat[1][1]*beg[1]; while(s2<0) s2+=MOD; s2%=MOD; return s2;}int main(){ int T; scanf("%d",&T); ll n; while(T--){ scanf("%lld",&n); printf("%lld\n",get(n)); }}
- HDU 6172-Array Challenge
- HDU 6172 Array Challenge(靠猜)
- HDU 6172 Array Challenge 【线性递推式模板】
- HDU 6172 Array Challenge 找规律+矩阵快速幂
- HDU 6172 Array Challenge【推公式/猜+矩阵快速幂】
- HDU 6172 Array Challenge(打表找规律+构造矩阵)
- Array Challenge
- 2017 Multi-University Training Contest 10 1002 Array Challenge HDU 6172(找规律 矩阵快速幂)
- HDU 6172 Array Challenge(打表+矩阵快速幂)——2017 Multi-University Training Contest
- HDU-2017 多校训练赛10-1002-Array Challenge
- HDU 6172 Array Challenge (打表找规律+矩阵快速幂 17多校第十场第2题)
- HDU6172-Array Challenge
- HDU6172 Array Challenge
- HDU6172-Array Challenge
- HDU 6127 Hard challenge
- hdu 6127 Hard challenge
- hdu--6127--Hard challenge
- HDU 6127 Hard challenge
- 装饰模式
- Eclipse环境下如何消除JSTL <c:out>标签出现的”Multiple annotations found at this line“告警
- Dubbo_特性2
- 2017 Multi-University Training Contest
- sc2017新高二&高一模拟赛9 总结
- HDU 6172-Array Challenge
- 红黑树
- 图结构练习——最短路径
- Spring Boot(二):从Session中获取域对象的三种方法
- Linux解压缩文件,安装文件
- HTML5利用canvas绘制动态信号瀑布图
- HDU6181-Two Paths【A*算法or次短路】
- 机器学习之KNN(k-nearest-neighbor)算法
- HDU 1358 Period [kmp]