結果

問題 No.2545 Divide by 3
ユーザー koba-e964koba-e964
提出日時 2023-12-11 11:00:19
言語 Rust
(1.77.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 981 bytes
コンパイル時間 385 ms
コンパイル使用メモリ 147,656 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-12-11 11:00:21
合計ジャッジ時間 1,466 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 1 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// https://yukicoder.me/problems/no/2545 (3.5)
// https://nu50218.dev/posts/integer-division-by-multiplication/ の議論を使うことで、
// (x * 0x5555_5556) >> 32 が答えであることがわかる。
// x * 0x5555_5556 は常に 2^62 以下であるため問題ない。
fn main() {
    println!("67");

    // A[4] = 5x
    println!("plus 5 1 1");
    println!("plus 5 5 5");
    println!("plus 4 1 5");

    // A[4] = 0x55 * x
    println!("plus 5 4 4");
    println!("plus 5 5 5");
    println!("plus 5 5 5");
    println!("plus 5 5 5");
    println!("plus 4 4 5");

    // A[4] = 0x5555 * x
    println!("plus 5 4 4");
    for _ in 1..8 {
        println!("plus 5 5 5");
    }
    println!("plus 4 4 5");

    // A[4] = 0x55555555 * x
    println!("plus 5 4 4");
    for _ in 1..16 {
        println!("plus 5 5 5");
    }
    println!("plus 4 4 5");

    // A[3] = 0x55555556 * x
    println!("plus 3 4 1");

    for _ in 0..32 {
        println!("div 3 3");
    }
}
0