結果
| 問題 |
No.1800 Random XOR
|
| コンテスト | |
| ユーザー |
Nachia
|
| 提出日時 | 2022-01-07 21:51:43 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 2,385 bytes |
| コンパイル時間 | 1,935 ms |
| コンパイル使用メモリ | 101,592 KB |
| 最終ジャッジ日時 | 2025-01-27 09:22:01 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 14 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
#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(){
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;
}
struct ios_do_not_sync{
ios_do_not_sync(){
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
}
} ios_do_not_sync_instance;
Nachia