• 2020牛客多校 第六场B


    规律题,在OEIS查了一下,找到了这个,所以说$f(i) = frac{(2^i - 2^{i-1}) (2 ^ i - 2 ^ {i-2}) ..... (2 ^ i - 2 ^ 0)}{(2 ^ i) ^ i}$

    列出:

    $f(i) = frac{(2 ^ i - 2 ^ 0) (2 ^ i - 2 ^ 1).......(2^i - 2^{i-1})}{(2 ^ i) ^ i} = frac{(2 ^ {i + 1} - 2 ^ 1) (2 ^ {i + 1} - 2 ^ 2).......(2^{i + 1} - 2^ i)}{(2 ^ i) ^ {i + 1}}$

    即$f(i) = frac{(2 ^ {i + 1} - 2 ^ 1) (2 ^ {i + 1} - 2 ^ 2).......(2^{i + 1} - 2^ i)}{(2 ^ {i + 1}) ^ i}$

    $f(i + 1) = frac{(2 ^ {i + 1} - 2 ^ 0) (2 ^ {i + 1} - 2 ^ 1)(2 ^ {i + 1} - 2 ^ 2).......(2^{i + 1} - 2^ i)}{(2 ^ {i + 1}) ^ {i + 1}}$

    可推出$f(i + 1) = f(i) * frac{2 ^ {i + 1} - 2 ^0 }{2 ^ {i + 1}}$

    Code:

    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    
    using namespace std;
    
    typedef long long ll;
    
    const int N = 2e7 + 10;
    const int mod = 1e9 + 7;
    
    ll qmi(ll a, ll b, ll p){
        ll res = 1;
        while(b){
            if(b & 1) res = res * a % p;
            a = a * a % p;
            b >>= 1;
        }
        return res;
    }
    
    ll ans[N], res[N];
    
    void init(){
        res[0] = 1;
        ll k = 1, infact = 1, mid = qmi(2, mod - 2, mod);
        for(int i = 1; i <= N - 10; i ++){
            k = k * 2 % mod;
            infact = infact * mid % mod;
            res[i] = res[i - 1] * (k - 1 + mod) % mod * infact % mod;
        }
        ans[1] = res[1];
        for(int i = 2; i <= N - 10; i ++){
            ans[i] = res[i] ^ ans[i - 1];
        }
    }
    
    void solve(){
        int n;
        scanf("%d", &n);
        printf("%lld
    ",ans[n]);
    }
    
    int main(){
        int t = 1;
        scanf("%d", &t);
        
        init();
        while(t --){
            solve();
        }
        return 0;
    }
  • 相关阅读:
    python 读取excel表格中的数据
    python 安装 pip 报错解决方案
    HDU-1150-MachineSchedule(二分图匹配)
    POJ-3177-RedundantPaths(边联通分量,缩点)
    POJ-3352-RoadConstruction(边双联通分量,缩点)
    F-三生三世
    D-温暖的签到题
    C-晾衣服
    A-坐飞机
    POJ-2777-CountColor(线段树,位运算)
  • 原文地址:https://www.cnblogs.com/jungu/p/13396151.html
Copyright © 2020-2023  润新知