結果
問題 | No.1006 Share an Integer |
ユーザー | tzyvrn |
提出日時 | 2020-03-06 22:33:58 |
言語 | Rust (1.77.0 + proconio) |
結果 |
TLE
|
実行時間 | - |
コード長 | 3,274 bytes |
コンパイル時間 | 13,235 ms |
コンパイル使用メモリ | 376,268 KB |
実行使用メモリ | 10,496 KB |
最終ジャッジ日時 | 2024-10-14 08:43:38 |
合計ジャッジ時間 | 19,189 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
10,496 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 1 ms
5,248 KB |
testcase_03 | AC | 1 ms
5,248 KB |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | AC | 3 ms
5,248 KB |
testcase_06 | AC | 3 ms
5,248 KB |
testcase_07 | AC | 3 ms
5,248 KB |
testcase_08 | AC | 3 ms
5,248 KB |
testcase_09 | AC | 4 ms
5,248 KB |
testcase_10 | AC | 3 ms
5,248 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 | -- | - |
コンパイルメッセージ
warning: variable does not need to be mutable --> src/main.rs:21:13 | 21 | let mut s = { | ----^ | | | help: remove this `mut` ... 66 | / input! { 67 | | x: usize, 68 | | } | |_____- in this macro invocation | = note: `#[warn(unused_mut)]` on by default = note: this warning originates in the macro `input` (in Nightly builds, run with -Z macro-backtrace for more info)
ソースコード
use std::collections::HashMap; #[allow(unused_imports)] use std::io::Write; // {{{1 #[allow(unused)] macro_rules! debug { ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap()); } #[allow(unused)] macro_rules! debugln { ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap()); } macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); input_inner!{iter, $($r)*} }; ($($r:tt)*) => { let mut s = { use std::io::Read; let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); s }; let mut iter = s.split_whitespace(); input_inner!{iter, $($r)*} }; } macro_rules! input_inner { ($iter:expr) => {}; ($iter:expr, ) => {}; ($iter:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($iter, $t); input_inner!{$iter $($r)*} }; } macro_rules! read_value { ($iter:expr, ( $($t:tt),* )) => { ( $(read_value!($iter, $t)),* ) }; ($iter:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>() }; ($iter:expr, chars) => { read_value!($iter, String).chars().collect::<Vec<char>>() }; ($iter:expr, usize1) => { read_value!($iter, usize) - 1 }; ($iter:expr, $t:ty) => { $iter.next().unwrap().parse::<$t>().expect("Parse error") }; } // }}} fn main() { input! { x: usize, } let solve = Solve::new(); let mut v = vec![]; let mut min = std::isize::MAX; for i in 1..x { let a = i; let b = x - i; let tmp = (solve.f(a) as isize - solve.f(b) as isize).abs(); if tmp == min { v.push((a, b)); } else if tmp < min { min = tmp; v = vec![(a, b)]; } } for (a, b) in v { println!("{} {}", a, b); } } struct Solve { primes: Vec<usize>, } impl Solve { fn new() -> Solve { let n = 2_000_000; let primes = prime_sieve((n as f64).sqrt() as usize); Solve { primes } } fn prime_factor(&self, n: usize) -> HashMap<usize, usize> { let mut factors = HashMap::new(); let primes = &self.primes; let mut rest = n; for &p in primes { while rest % p == 0 { let count = factors.entry(p).or_insert(0); *count += 1; rest /= p; } } if rest != 1 { factors.insert(rest, 1); } factors } fn f(&self, n: usize) -> usize { let factors = self.prime_factor(n); let mut d = 1; for (_, e) in factors { d *= e + 1; } n - d } } fn prime_sieve(n: usize) -> Vec<usize> { let mut table: Vec<usize> = vec![0; (n + 1) as usize]; let mut primes: Vec<usize> = Vec::new(); for i in 2..(n + 1) { if table[i as usize] == 0 { primes.push(i); for j in 2..n { if i * j > n { break; } table[(i * j) as usize] = 1 } } } primes }