結果

問題 No.1006 Share an Integer
ユーザー uw_yu1rabbituw_yu1rabbit
提出日時 2021-03-14 01:51:24
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,315 bytes
コンパイル時間 807 ms
コンパイル使用メモリ 171,952 KB
実行使用メモリ 13,888 KB
最終ジャッジ日時 2024-04-23 14:31:08
合計ジャッジ時間 4,421 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,860 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 WA -
testcase_04 AC 1 ms
6,940 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 1 ms
6,940 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 #

#[allow(dead_code)]
#[allow(unused_imports)]
fn read<T: std::str::FromStr>() -> T {
    use std::io::*;
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}
fn enum_divisors(n:i64) -> i64 {
    let mut res = Vec::new();
    let mut i = 1;
    while i * i <= n {
        if n % i == 0 {
            res.push(i);
            if n / i != i {
                res.push(n/i);
            }
        }
        i += 1;
    }
    res.len() as i64
}
fn main(){
    let x:i64 = read();
    let mut ans = 1e18 as i64;
    let mut rec = Vec::new();
    for i in 1..= x / 2 {
        let a = i - enum_divisors(i);
        let b = x - i - enum_divisors(x - i);
        ans = std::cmp::min(ans,(a - b).abs());
    }
    for i in 1..= x/ 2 {
        let a = i -  enum_divisors(i as i64);
        let b = x - i - enum_divisors(x as i64 - i as i64);
        if (a - b).abs() == ans {
            rec.push((i,x - i));
            rec.push((x - i,i));
        }
    }
    rec.sort();
    for i in 0..rec.len() {
        println!("{} {}",rec[i].0, rec[i].1);
    }
}
0