結果
| 問題 | 
                            No.1800 Random XOR
                             | 
                    
| コンテスト | |
| ユーザー | 
                             Nachia
                         | 
                    
| 提出日時 | 2024-04-26 18:56:28 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 5 ms / 2,000 ms | 
| コード長 | 2,295 bytes | 
| コンパイル時間 | 749 ms | 
| コンパイル使用メモリ | 73,356 KB | 
| 最終ジャッジ日時 | 2025-02-21 09:10:19 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 14 | 
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)
template<u32 MOD>
struct LazyMontgomeryModint{
private:
    static constexpr u32 get_ninv(){
        u32 res = 0;
        u32 t = 0;
        for(u32 d=0; d<32; d++){
            if(!(t & 1)){ t += MOD; res |= (u32)1 << d; }
            t >>= 1;
        }
        return res;
    }
    static constexpr u32 get_r2(){
        u64 r2 = ((u64)1 << 32) % MOD; r2 = (u64)r2 * r2 % MOD;
        return r2;
    }
    static u32 montgomery_reduction(u64 t){
        u32 ninv = get_ninv();
        t = (t + (u64)(u32)((u32)t * ninv) * MOD) >> 32;
        if(t >= MOD) t -= MOD;
        return t;
    }
    u32 x;
public:
    using my_type = LazyMontgomeryModint;
    LazyMontgomeryModint() : x(0){}
    LazyMontgomeryModint(u32 v) : x(montgomery_reduction((u64)v * get_r2())){}
    u32 operator*() const { return montgomery_reduction(x); }
    my_type& operator+=(const my_type& r){ x += r.x; if(x >= MOD) x -= MOD; return *this; }
    my_type operator+(const my_type& r) const { my_type res = *this; return res += r; }
    my_type& operator-=(const my_type& r){ x += MOD - r.x; if(x >= MOD) x -= MOD; return *this; }
    my_type operator-(const my_type& r) const { my_type res = *this; return res -= r; }
    my_type operator-() const { my_type res = *this; res.x = ((res.x == 0) ? 0 : (MOD - res.x)); return res; }
    my_type& operator*=(const my_type& r){ x = montgomery_reduction((u64)x * r.x); return *this; }
    my_type operator*(const my_type& r) const { my_type res = *this; return res *= r; }
    my_type pow(u64 i) const {
        my_type a = *this, res = 1;
        while(i){ if(i & 1) res *= a; a *= a; i >>= 1; }
        return res;
    }
    my_type inv() const { return pow(MOD-2); }
    u32 val() const { return **this; }
    static u32 get_mod() { return MOD; }
};
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    u64 N,M; cin >> N >> M;
    N %= 1000000007;
    using modint = LazyMontgomeryModint<1000000007>;
    modint ans = 2;
    ans = ans.pow(M);
    ans -= 1;
    ans *= modint(2).inv();
    cout << *ans << endl;
    return 0;
}
            
            
            
        
            
Nachia