結果
問題 | No.847 Divisors of Power |
ユーザー | pianoneko |
提出日時 | 2019-08-02 23:12:43 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 3,299 bytes |
コンパイル時間 | 13,507 ms |
コンパイル使用メモリ | 389,140 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-07 03:00:35 |
合計ジャッジ時間 | 14,479 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 1 ms
6,820 KB |
testcase_02 | AC | 1 ms
6,816 KB |
testcase_03 | AC | 1 ms
6,816 KB |
testcase_04 | AC | 1 ms
6,820 KB |
testcase_05 | AC | 1 ms
6,816 KB |
testcase_06 | AC | 1 ms
6,816 KB |
testcase_07 | AC | 1 ms
6,820 KB |
testcase_08 | AC | 1 ms
6,820 KB |
testcase_09 | AC | 1 ms
6,816 KB |
testcase_10 | AC | 1 ms
6,816 KB |
testcase_11 | AC | 1 ms
6,816 KB |
testcase_12 | AC | 1 ms
6,820 KB |
testcase_13 | AC | 1 ms
6,816 KB |
testcase_14 | AC | 1 ms
6,820 KB |
testcase_15 | AC | 3 ms
6,820 KB |
testcase_16 | AC | 1 ms
6,820 KB |
testcase_17 | AC | 1 ms
6,816 KB |
testcase_18 | AC | 1 ms
6,820 KB |
testcase_19 | AC | 1 ms
6,816 KB |
testcase_20 | AC | 1 ms
6,816 KB |
testcase_21 | AC | 1 ms
6,816 KB |
testcase_22 | AC | 1 ms
6,820 KB |
testcase_23 | AC | 1 ms
6,820 KB |
testcase_24 | AC | 3 ms
6,820 KB |
testcase_25 | AC | 1 ms
6,820 KB |
testcase_26 | AC | 1 ms
6,820 KB |
testcase_27 | AC | 1 ms
6,820 KB |
testcase_28 | AC | 1 ms
6,820 KB |
testcase_29 | AC | 1 ms
6,820 KB |
コンパイルメッセージ
warning: unused import: `std::collections::*` --> src/main.rs:2:5 | 2 | use std::collections::*; | ^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default warning: function `read` is never used --> src/main.rs:22:4 | 22 | fn read<T: FromStr>() -> T { | ^^^^ | = note: `#[warn(dead_code)]` on by default
ソースコード
use std::cmp::*; use std::collections::*; use std::fmt::Debug; use std::io::{stdin, Read}; use std::str::FromStr; #[derive(Eq, PartialEq, Clone, Debug)] pub struct Rev<T>(pub T); impl<T: PartialOrd> PartialOrd for Rev<T> { fn partial_cmp(&self, other: &Rev<T>) -> Option<Ordering> { other.0.partial_cmp(&self.0) } } impl<T: Ord> Ord for Rev<T> { fn cmp(&self, other: &Rev<T>) -> Ordering { other.0.cmp(&self.0) } } 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") } macro_rules! read { (($($t:tt),*)) => { ( $(read!($t)),* ) }; ([[$t:tt; $len1:expr]; $len2:expr]) => { (0..$len2).map(|_| read!([$t; $len1])).collect::<Vec<_>>() }; ([$t:tt; $len:expr]) => { (0..$len).map(|_| read!($t)).collect::<Vec<_>>() }; (chars) => { read!(String).chars().collect::<Vec<char>>() }; (usize1) => { read!(usize) - 1 }; ($t:ty) => {{ let stdin = stdin(); let stdin = stdin.lock(); let token: String = stdin .bytes() .map(|c| c.unwrap() as char) .skip_while(|c| c.is_whitespace()) .take_while(|c| !c.is_whitespace()) .collect(); token.parse::<$t>().unwrap() }}; } macro_rules! input { (mut $name:ident: $t:tt, $($r:tt)*) => { let mut $name = read!($t); $(println!("{}", stringify!($r));)* input!($($r)*); }; (mut $name:ident: $t:tt) => { let mut $name = read!($t); }; ($name:ident: $t:tt, $($r:tt)*) => { let $name = read!($t); input!($($r)*); }; ($name:ident: $t:tt) => { let $name = read!($t); }; } pub fn prime_factorize(_n: &u64) -> Vec<(u64, usize)> { let mut n = _n.clone(); let mut res = Vec::new(); for p in 2..((*_n as f64).sqrt() as u64) + 1 { if n % p != 0 { continue; } let mut num = 0; while n % p == 0 { num += 1; n /= p; } res.push((p, num)); } if n != 1 { res.push((n, 1)); } return res; } fn main() { input!(n: u64, k: u64, m: u64); let factors = prime_factorize(&n); struct SolveEnv { factors: Vec<(u64, usize)>, k: u64, m: u64, } let env = SolveEnv { factors: factors, k: k, m: m, }; fn solve(env: &SolveEnv, i: usize, num: u64) -> u64 { if i == env.factors.len() { if num <= env.m { return 1; } else { return 0; } } let mut res = 0; for count in 0..(env.factors[i].1 * env.k as usize + 1) { let next = num * env.factors[i].0.pow(count as u32); if next <= env.m { res += solve(env, i + 1, next); } else { break; } } return res; } println!("{}", solve(&env, 0, 1)); }