結果

問題 No.1800 Random XOR
ユーザー 👑 NachiaNachia
提出日時 2024-04-26 18:56:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,295 bytes
コンパイル時間 1,362 ms
コンパイル使用メモリ 77,856 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-26 18:56:31
合計ジャッジ時間 1,551 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0