結果

問題 No.1006 Share an Integer
ユーザー uw_yu1rabbituw_yu1rabbit
提出日時 2020-08-27 22:18:57
言語 Rust
(1.77.0)
結果
TLE  
実行時間 -
コード長 1,301 bytes
コンパイル時間 1,186 ms
コンパイル使用メモリ 172,264 KB
実行使用メモリ 70,500 KB
最終ジャッジ日時 2024-04-26 02:18:26
合計ジャッジ時間 4,464 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

use std::io::*;
use std::cmp::*;
use std::str::FromStr;
#[allow(unused_imports)]
fn read<T: FromStr>() -> T {
    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 primes(n:usize) -> usize{
    let mut cnt:usize = 0;
    let root:usize =((n as f64).sqrt()) as usize;
    for i in 1..root + 1{
        match n % i {
            0 => cnt += 1,
            _ => cnt += 0,
        }
        if n / i != i && n % i == 0{
            cnt += 1
        }
    }
    cnt
}
fn main(){
    let x:usize = read();
    let mut rec = vec![0;x + 1];
    for i in 1..x {
        rec[i] = primes(i);
    }
    let mut ans:Vec<Vec<(usize,usize)>> = vec![vec![(0,0);0];x + 1];
    let mut mini = 100000000000000000;
    for i in 1..x{
        let fn_s:i64 = (i as i64 - rec[i] as i64) as i64;
        let fn_b:i64 = ((x - i) as i64 - rec[x - i] as i64) as i64;
        let tmp = (fn_s - fn_b).abs() as usize;
        mini = min(mini,tmp);
        ans[tmp].push((i,x - i));
    }
    for i in &ans[mini] {
        println!("{} {}", i.0,i.1);
    }
}
0