Problem of Precision solution
question:
InputThe 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)
OutputFor each input case, you should output the answer in one line.
Sample Input
3 1 2 5
Sample Output9
97 841
#include <cstdio>
using namespace std; const int maxx = 1024; int n; struct math { int s[2][2]; math(int a = 0, int b = 0, int c = 0, int d = 0) { s[0][0] = a; s[0][1] = b; s[1][0] = c; s[1][1] = d; } math operator * (const math& c) { math as; for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) for (int k = 0; k < 2; k++) as.s[i][j] = (as.s[i][j] + s[i][k] * c.s[k][j]) % maxx; return as; } }tmp(5, 12, 2, 5); math pow_mod(int k) { if (k == 1) return tmp; math a = pow_mod(k / 2); math as = a * a; if (k % 2) as = as * tmp; return as; } int main() { int cas; scanf("%d", &cas); while (cas--) { scanf("%d", &n); math as = pow_mod(n); printf("%d\n", (as.s[0][0] * 2 - 1) % maxx); } return 0;