hdu 2256-Problem of Precision
2014-07-30 11:04
435 查看
Description
![](http://acm.hdu.edu.cn/data/images/C142-1010-1.jpg)
Input
The first line of input gives the number of cases, T. T test cases follow, each on a separate line. Each test case contains one positive integer n. (1 <= n <= 10^9)
Output
For each input case, you should output the answer in one line.
Sample Input
3
1
2
5
---------------------------------------------------------------------------------------
看了题解才会的题`~~特别巧妙!
![](https://img-blog.csdn.net/20140730110259164)
CODE:
![](http://acm.hdu.edu.cn/data/images/C142-1010-1.jpg)
Input
The first line of input gives the number of cases, T. T test cases follow, each on a separate line. Each test case contains one positive integer n. (1 <= n <= 10^9)
Output
For each input case, you should output the answer in one line.
Sample Input
3
1
2
5
---------------------------------------------------------------------------------------
看了题解才会的题`~~特别巧妙!
CODE:
#include <iostream> #include <cstdio> #include <algorithm> #include <cmath> #include <string> #include <cstring> #include <queue> #include <stack> #include <vector> #include <set> #include <map> const int inf=0xfffffff; typedef long long ll; using namespace std; const int mod=1024; typedef vector<int> vec; typedef vector<vec> mat; mat mul(mat &A,mat &B) { mat C(A.size(),vec(B.size())); for(int i=0;i<A.size();i++){ for(int k=0;k<B.size();k++){ for(int j=0;j<B[0].size();j++){ C[i][j] = (C[i][j] + A[i][k]*B[k][j])%mod; } } } return C; } mat pow(mat &A,int nn) { mat B(A.size(),vec(A.size())); for(int i=0;i<A.size();i++) B[i][i] = 1; while(nn > 0){ if(nn & 1) B = mul(B,A); A = mul(A,A); nn >>= 1; } return B; } int main() { //freopen("in.in","r",stdin); int T,n; scanf("%d",&T); while(T--){ int n; scanf("%d",&n); mat A(2,vec(2)); A[0][0] = 5;A[0][1] = 12; A[1][0] = 2;A[1][1] = 5; A = pow(A,n-1); int ans = 0; ans = (A[0][0]*5+A[0][1]*2)%mod; printf("%d\n", (2*ans-1)%mod); } return 0; }
相关文章推荐
- hdu 2256 Problem of Precision -矩阵快速幂
- HDU 2256 Problem of Precision 构造矩阵
- HDU 2256 Problem of Precision(矩阵快速幂)
- HDU 2256 Problem of Precision(矩阵快速幂)
- HDU 2256 Problem of Precision(找规律+矩阵)
- HDU 2256 Problem of Precision (矩阵快速幂)
- hdu 2256 Problem of Precision(矩阵乘法)
- hdu 2256 Problem of Precision(矩阵快速幂,得出递推式有难度)
- HDU2256-Problem of Precision(矩阵构造+高速幂)
- hdu 2256 Problem of Precision(矩阵乘法+共轭公式)
- hdu 2256 Problem of Precision 矩阵
- HDU 2256 Problem of Precision
- Hdu 2256 Problem of Precision[矩阵快速幂 + 数学]
- HDU 2256 Problem of Precision (矩阵快速幂)
- HDU 2256 Problem of Precision 解题报告(矩阵快速幂 + 构造)
- HDU 2256 Problem of Precision 数论矩阵快速幂
- HDU_2256_Problem of Precision
- hdu 2256 Problem of Precision
- hdu 2256 Problem of Precision 矩阵快速幂
- HDU 2256 Problem of Precision