Problem of Precision
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2127 Accepted Submission(s): 1304
Problem Description
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
Sample Output
9
97
841
Source
Recommend
#include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <iostream> #include <algorithm> #include <iostream> #include<cstdio> #include<string> #include<cstring> #include <stdio.h> #include <queue> #include <string.h> #include <vector> #define ME(x , y) memset(x , y , sizeof(x)) #define SF(n) scanf("%d" , &n) #define rep(i , n) for(int i = 0 ; i < n ; i ++) #define INF 0x3f3f3f3f #define mod 1024 using namespace std; typedef long long ll ; struct node{ int a[2][2]; node() { memset(a , 0 , sizeof(a)); } }; node mul(node A , node B) { node C ; for(int i = 0 ; i < 2 ; i ++) { for(int j = 0 ; j < 2 ; j++) { for(int k = 0 ; k < 2 ; k++) { C.a[i][j] = (C.a[i][j] + A.a[i][k] * B.a[k][j]) % mod; } } } return C; } node pow1(node A , int m) { node ans ; for(int i = 0 ; i < 2 ; i++) ans.a[i][i] = 1 ; while(m) { if(m&1) { ans = mul(ans , A); } m >>= 1 ; A = mul(A , A); } return ans ; } int main() { int t ; scanf("%d" , &t); while(t--) { int n ; scanf("%d" , &n); node A ,B ,C ; A.a[0][0] = 5 , A.a[0][1] = 12 ; A.a[1][0] = 2 , A.a[1][1] = 5 ; B.a[0][0] = 5 , B.a[1][0] = 2 ; C = mul(pow1(A , n-1) , B); printf("%d " , (C.a[0][0]*2 - 1)%mod); } return 0 ; }