結果

問題 No.1006 Share an Integer
ユーザー tonyu0tonyu0
提出日時 2020-03-31 19:55:39
言語 Rust
(1.77.0)
結果
AC  
実行時間 10 ms / 2,000 ms
コード長 1,715 bytes
コンパイル時間 1,560 ms
コンパイル使用メモリ 151,108 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-07 06:27:18
合計ジャッジ時間 2,713 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 7 ms
4,380 KB
testcase_12 AC 9 ms
4,380 KB
testcase_13 AC 9 ms
4,380 KB
testcase_14 AC 10 ms
4,380 KB
testcase_15 AC 8 ms
4,384 KB
testcase_16 AC 6 ms
4,380 KB
testcase_17 AC 7 ms
4,380 KB
testcase_18 AC 9 ms
4,380 KB
testcase_19 AC 8 ms
4,380 KB
testcase_20 AC 8 ms
4,380 KB
testcase_21 AC 9 ms
4,380 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 n: i64 = itr.next().unwrap().parse().unwrap();

    let mut d = vec![0i64; n as usize + 2];
    d[1] = 1;
    let mut range = n / 2 - 1;
    if n > 10000 {
        range = 1000;
    }
    for m in n / 2 - range..n / 2 + 1 {
        // 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;
        }
        // n - mの約数
        let mut i = 1;
        let c = &mut d[(n - m) as usize];
        *c += n - m;
        while i * i <= m {
            if (n - m) % i == 0 {
                if (n - m) / i == (n - m) / ((n - m) / i) {
                    *c -= 1;
                } else {
                    *c -= 2;
                }
            }
            i += 1;
        }
    }

    let mut min = 1 << 30;
    for i in n / 2 - range..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 n / 2 - range..n / 2 + 1 {
        if (d[(n - i) as usize] - d[i as usize]).abs() == min {
            ans.push((i, n - i));
            if 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