結果

問題 No.1006 Share an Integer
ユーザー tonyu0tonyu0
提出日時 2020-04-02 00:08:22
言語 Rust
(1.77.0)
結果
AC  
実行時間 124 ms / 2,000 ms
コード長 766 bytes
コンパイル時間 3,259 ms
コンパイル使用メモリ 143,348 KB
実行使用メモリ 17,584 KB
最終ジャッジ日時 2023-09-09 20:24:28
合計ジャッジ時間 5,582 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 55 ms
10,656 KB
testcase_12 AC 113 ms
16,552 KB
testcase_13 AC 124 ms
17,560 KB
testcase_14 AC 123 ms
17,584 KB
testcase_15 AC 102 ms
15,324 KB
testcase_16 AC 37 ms
8,416 KB
testcase_17 AC 59 ms
10,892 KB
testcase_18 AC 105 ms
15,228 KB
testcase_19 AC 92 ms
14,740 KB
testcase_20 AC 102 ms
15,764 KB
testcase_21 AC 121 ms
17,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let x: i64 = itr.next().unwrap().parse().unwrap();

    let mut f: Vec<i64> = (0..x + 5).collect();
    for i in 1..x + 1 {
        let mut j = i;
        while j <= x + 1 {
            f[j as usize] -= 1;
            j += i;
        }
    }

    let mut min = 1 << 30;
    let mut out = Vec::new();
    for i in 1..x {
        min = std::cmp::min(min, (f[(x - i) as usize] - f[i as usize]).abs());
    }
    for i in 1..x {
        if (f[(x - i) as usize] - f[i as usize]).abs() == min {
            writeln!(out, "{} {}", i, x - i).ok();
        }
    }
    stdout().write_all(&out).unwrap();
}
0