結果

問題 No.1800 Random XOR
ユーザー Masaki Kitaguchi
提出日時 2022-01-16 07:42:39
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,502 bytes
コンパイル時間 16,382 ms
コンパイル使用メモリ 378,196 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-22 21:51:18
合計ジャッジ時間 13,596 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

#[macro_export]
macro_rules! setup {
    { mut $input:ident: SplitWhitespace $(,)? } => {
        use std::io::Read;
        let mut buf = String::new();
        std::io::stdin().read_to_string(&mut buf).ok();
        let mut $input = buf.split_whitespace();
    };
}

#[macro_export]
macro_rules! parse_next {
    ($str_iter:expr) => {
        $str_iter.next().unwrap().parse().ok().unwrap()
    };
}

fn main() {
    setup! { mut input: SplitWhitespace };

    let _n: u64 = parse_next!(input);
    let m: u64 = parse_next!(input);

    const MOD: u64 = 1000000007;

    macro_rules! b {
        ($i:expr, $op:tt, $j:expr) => {
            b!($i, $op, $j, MOD)
        };
        ($i:expr, +, $j:expr, $mod:expr) => {
            ($i + $j) % $mod
        };
        ($i:expr, -, $j:expr, $mod:expr) => {{
            ($i + $mod - $j) % $mod
        }};
        ($i:expr, *, $j:expr, $mod:expr) => {
            ($i * $j) % $mod
        };
        ($i:expr, /, $j:expr, $mod:expr) => {
            b!($i, *, b!($j, ^, $mod - 2, $mod), $mod)
        };
        ($i:expr, ^, $j:expr, $mod:expr) => {{
            let mut a = $i;
            let mut n = $j;
            let mut ret = 1;
            while n > 0 {
                if n & 1 == 1 {
                    ret = b!(ret, *, a, $mod);
                }
                a = b!(a, *, a, $mod);
                n >>= 1;
            }
            ret
        }};
    }

    let e = b!(b!(b!(2, ^, m), -, 1), *, b!(1, /, 2));

    println!("{}", e);
}
0