結果
| 問題 | No.1006 Share an Integer |
| コンテスト | |
| ユーザー |
uw_yu1rabbit
|
| 提出日時 | 2021-03-14 01:51:24 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,315 bytes |
| 記録 | |
| コンパイル時間 | 23,237 ms |
| コンパイル使用メモリ | 378,680 KB |
| 実行使用メモリ | 10,496 KB |
| 最終ジャッジ日時 | 2024-10-15 14:43:31 |
| 合計ジャッジ時間 | 18,235 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 4 WA * 4 TLE * 1 -- * 10 |
ソースコード
#[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);
}
}
uw_yu1rabbit