結果
| 問題 |
No.1006 Share an Integer
|
| コンテスト | |
| ユーザー |
uw_yu1rabbit
|
| 提出日時 | 2021-03-14 01:57:44 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 168 ms / 2,000 ms |
| コード長 | 1,130 bytes |
| コンパイル時間 | 13,008 ms |
| コンパイル使用メモリ | 377,164 KB |
| 実行使用メモリ | 17,536 KB |
| 最終ジャッジ日時 | 2024-10-15 14:44:35 |
| 合計ジャッジ時間 | 15,383 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 |
コンパイルメッセージ
warning: variable does not need to be mutable --> src/main.rs:16:9 | 16 | let mut x:usize = read(); | ----^ | | | help: remove this `mut` | = note: `#[warn(unused_mut)]` on by default
ソースコード
#[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 main(){
let mut x:usize = read();
let mut f:Vec<_> = (0..=x).map(|i| i as i64).collect();
for i in 1..=x {
f[i] -= 1;
let mut mul = 2;
while i * mul <= x {
f[i * mul] -= 1;
mul += 1;
}
}
let mut res = Vec::new();
let mut ans = 1e18 as i64;
for i in 1..=x/2 {
ans = std::cmp::min(ans,(f[i] - f[x - i]).abs());
}
for i in 1..=x/2 {
if ans == (f[i] - f[x - i]).abs() {
res.push((i,x - i));
if i != x - i {
res.push((x - i,i));
}
}
}
res.sort();
for i in 0..res.len() {
println!("{} {}",res[i].0,res[i].1);
}
}
uw_yu1rabbit