提出 #36973858
ソースコード 拡げる
#![allow(unused_imports)] use std::cmp::*; use std::collections::*; use std::io::Write; use std::ops::Bound::*; #[allow(unused_macros)] macro_rules! debug { ($($e:expr),*) => { #[cfg(debug_assertions)] $({ let (e, mut err) = (stringify!($e), std::io::stderr()); writeln!(err, "{} = {:?}", e, $e).unwrap() })* }; } fn main() { let k = read::<i64>(); let mut k2 = k; for i in 2..=2000000 { let g = gcd(k2, i); if k2 % g == 0 { k2 /= g; } if k2 == 1 { println!("{}", i); return; } } println!("{}", k2); } fn gcd(a: i64, b: i64) -> i64 { if b == 0 { return a; } gcd(b, a % b) } type Input = i64; fn binary_search<F>(lb: Input, ub: Input, criterion: F) -> (Input, Input) where F: Fn(Input) -> bool, { assert_eq!(criterion(lb), true); assert_eq!(criterion(ub), false); let mut ok = lb; let mut ng = ub; while ng - ok > 1 { let mid = (ng + ok) / 2; if criterion(mid) { ok = mid; } else { ng = mid; } } (ok, ng) } fn read<T: std::str::FromStr>() -> T { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim().parse().ok().unwrap() } fn read_vec<T: std::str::FromStr>() -> Vec<T> { read::<String>() .split_whitespace() .map(|e| e.parse().ok().unwrap()) .collect() } fn get_primes(n: i64) -> Vec<i64> { let mut is_prime = vec![true; n as usize + 1]; let mut primes = Vec::new(); is_prime[0] = false; is_prime[1] = false; for i in 2..n + 1 { if is_prime[i as usize] { primes.push(i); let mut j = 2 * i; while j <= n { is_prime[j as usize] = false; j += i; } } } primes } fn factorize(mut num: i64, primes: &Vec<i64>) -> std::collections::HashMap<i64, i64> { // max_primes >= (num)^(1/2) let num_org = num; let mut dict = std::collections::HashMap::new(); for &p in primes.iter() { while num % p == 0 { *dict.entry(p).or_insert(0) += 1; num /= p; } if num == 1 { break; } if p * p > num_org { *dict.entry(num).or_insert(0) += 1; break; } } if num != 1 { dict.insert(num, 1); } dict }
提出情報
提出日時 | |
---|---|
問題 | D - Factorial and Multiple |
ユーザ | ryoryoryo111 |
言語 | Rust (1.42.0) |
得点 | 400 |
コード長 | 2474 Byte |
結果 | AC |
実行時間 | 355 ms |
メモリ | 2168 KiB |
コンパイルエラー
warning: type alias is never used: `Input` --> src/main.rs:41:1 | 41 | type Input = i64; | ^^^^^^^^^^^^^^^^^ | = note: `#[warn(dead_code)]` on by default warning: function is never used: `binary_search` --> src/main.rs:42:4 | 42 | fn binary_search<F>(lb: Input, ub: Input, criterion: F) -> (Input, Input) | ^^^^^^^^^^^^^ warning: function is never used: `read_vec` --> src/main.rs:67:4 | 67 | fn read_vec<T: std::str::FromStr>() -> Vec<T> { | ^^^^^^^^ warning: function is never used: `get_primes` --> src/main.rs:74:4 | 74 | fn get_primes(n: i64) -> Vec<i64> { | ^^^^^^^^^^ warning: function is never used: `factorize` --> src/main.rs:93:4 | 93 | fn factorize(mut num: i64, primes: &Vec<i64>) -> std::collections::HashMap<i64, i64> { | ^^^^^^^^^
ジャッジ結果
セット名 | Sample | All | ||||
---|---|---|---|---|---|---|
得点 / 配点 | 0 / 0 | 400 / 400 | ||||
結果 |
|
|
セット名 | テストケース |
---|---|
Sample | example_00.txt, example_01.txt, example_02.txt |
All | example_00.txt, example_01.txt, example_02.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, hand_11.txt, hand_12.txt, hand_13.txt, hand_14.txt, hand_15.txt, hand_16.txt, hand_17.txt, hand_18.txt, hand_19.txt, hand_20.txt, hand_21.txt, hand_22.txt, hand_23.txt, hand_24.txt, hand_25.txt, hand_26.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt |
ケース名 | 結果 | 実行時間 | メモリ |
---|---|---|---|
example_00.txt | AC | 6 ms | 2024 KiB |
example_01.txt | AC | 348 ms | 1960 KiB |
example_02.txt | AC | 2 ms | 2112 KiB |
hand_00.txt | AC | 5 ms | 2084 KiB |
hand_01.txt | AC | 2 ms | 1900 KiB |
hand_02.txt | AC | 345 ms | 1960 KiB |
hand_03.txt | AC | 351 ms | 1960 KiB |
hand_04.txt | AC | 344 ms | 1936 KiB |
hand_05.txt | AC | 355 ms | 2104 KiB |
hand_06.txt | AC | 280 ms | 1968 KiB |
hand_07.txt | AC | 168 ms | 2092 KiB |
hand_08.txt | AC | 169 ms | 2028 KiB |
hand_09.txt | AC | 345 ms | 2040 KiB |
hand_10.txt | AC | 349 ms | 2104 KiB |
hand_11.txt | AC | 8 ms | 2000 KiB |
hand_12.txt | AC | 351 ms | 2028 KiB |
hand_13.txt | AC | 248 ms | 1960 KiB |
hand_14.txt | AC | 349 ms | 1996 KiB |
hand_15.txt | AC | 346 ms | 1996 KiB |
hand_16.txt | AC | 10 ms | 2004 KiB |
hand_17.txt | AC | 2 ms | 1948 KiB |
hand_18.txt | AC | 2 ms | 2040 KiB |
hand_19.txt | AC | 1 ms | 2040 KiB |
hand_20.txt | AC | 1 ms | 2024 KiB |
hand_21.txt | AC | 1 ms | 1972 KiB |
hand_22.txt | AC | 3 ms | 2044 KiB |
hand_23.txt | AC | 1 ms | 2044 KiB |
hand_24.txt | AC | 1 ms | 1996 KiB |
hand_25.txt | AC | 1 ms | 2028 KiB |
hand_26.txt | AC | 1 ms | 2060 KiB |
random_00.txt | AC | 1 ms | 1968 KiB |
random_01.txt | AC | 1 ms | 2068 KiB |
random_02.txt | AC | 1 ms | 2116 KiB |
random_03.txt | AC | 2 ms | 2088 KiB |
random_04.txt | AC | 2 ms | 1892 KiB |
random_05.txt | AC | 2 ms | 1976 KiB |
random_06.txt | AC | 1 ms | 2040 KiB |
random_07.txt | AC | 1 ms | 2168 KiB |
random_08.txt | AC | 2 ms | 2116 KiB |
random_09.txt | AC | 1 ms | 2056 KiB |
random_10.txt | AC | 1 ms | 2104 KiB |
random_11.txt | AC | 1 ms | 2116 KiB |
random_12.txt | AC | 1 ms | 1960 KiB |
random_13.txt | AC | 1 ms | 2064 KiB |
random_14.txt | AC | 1 ms | 2088 KiB |
random_15.txt | AC | 1 ms | 2040 KiB |
random_16.txt | AC | 1 ms | 2052 KiB |
random_17.txt | AC | 1 ms | 2040 KiB |
random_18.txt | AC | 2 ms | 2036 KiB |
random_19.txt | AC | 1 ms | 2032 KiB |
random_20.txt | AC | 11 ms | 2012 KiB |
random_21.txt | AC | 2 ms | 1968 KiB |
random_22.txt | AC | 348 ms | 2068 KiB |
random_23.txt | AC | 23 ms | 2048 KiB |
random_24.txt | AC | 350 ms | 2068 KiB |
random_25.txt | AC | 346 ms | 2120 KiB |
random_26.txt | AC | 74 ms | 2060 KiB |
random_27.txt | AC | 1 ms | 2060 KiB |
random_28.txt | AC | 1 ms | 2048 KiB |
random_29.txt | AC | 1 ms | 1992 KiB |
random_30.txt | AC | 2 ms | 2040 KiB |
random_31.txt | AC | 2 ms | 2004 KiB |
random_32.txt | AC | 47 ms | 1948 KiB |