zoukankan      html  css  js  c++  java
  • 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
    ", (as.s[0][0] * 2 - 1) % maxx); 
        }
        return 0;
  • 相关阅读:
    python读取二进制文件写入到txt
    python格式化输出
    字符编码
    python--随时记录
    python-web服务器
    openssh移植
    select、poll、epoll
    (总结)Nginx/LVS/HAProxy负载均衡软件的优缺点详解
    heartbeat与keepalived的区别
    salt 常用命令整理
  • 原文地址:https://www.cnblogs.com/hrlsm/p/13388440.html
Copyright © 2011-2022 走看看