結果

問題 No.1006 Share an Integer
ユーザー tonyu0tonyu0
提出日時 2020-03-31 17:37:12
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,169 bytes
コンパイル時間 3,318 ms
コンパイル使用メモリ 155,012 KB
実行使用メモリ 14,056 KB
最終ジャッジ日時 2023-09-07 02:44:40
合計ジャッジ時間 6,544 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,764 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 WA -
testcase_04 AC 1 ms
4,380 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

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 n: i64 = itr.next().unwrap().parse().unwrap();

    let mut d = vec![0i64; n as usize + 2];
    d[1] = 1;
    for m in 1..n {
        // mの約数の個数
        let mut i = 1;
        let c = &mut d[m as usize];
        *c += m;
        while i * i <= m {
            if m % i == 0 {
                if m / i == m / (m / i) {
                    *c -= 1;
                } else {
                    *c -= 2;
                }
            }
            i += 1;
        }
    }

    let mut min = 1 << 30;
    for i in 1..n / 2 + 1 {
        min = std::cmp::min(min, (d[(n - i) as usize] - d[i as usize]).abs());
    }

    let mut ans = Vec::new();
    for i in 1..n / 2 + 1 {
        if (d[(n - i) as usize] - d[i as usize]).abs() == min {
            ans.push((i, n - i));
            ans.push((n - i, i));
        }
    }
    ans.sort();
    let mut out = Vec::new();
    for &i in ans.iter() {
        writeln!(out, "{} {}", i.0, i.1).ok();
    }
    stdout().write_all(&out).unwrap();
}
0