首页 > 其他 > 详细

Problem of Precision solution

时间:2020-07-28 11:01:55      阅读:63      评论:0      收藏:0      [点我收藏+]

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 Output

9
97
841

solution:
#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; 
        sizeof(as.s, 0, sizeof(as.s));
        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;

 

Problem of Precision solution

原文:https://www.cnblogs.com/hrlsm/p/13388440.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!