結果
問題 | No.1973 Divisor Sequence |
ユーザー | cutmdo |
提出日時 | 2022-06-11 04:28:14 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 133 ms / 2,000 ms |
コード長 | 3,600 bytes |
コンパイル時間 | 13,093 ms |
コンパイル使用メモリ | 395,536 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-21 11:59:23 |
合計ジャッジ時間 | 14,753 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 14 ms
5,248 KB |
testcase_03 | AC | 6 ms
5,376 KB |
testcase_04 | AC | 10 ms
5,376 KB |
testcase_05 | AC | 14 ms
5,376 KB |
testcase_06 | AC | 11 ms
5,376 KB |
testcase_07 | AC | 9 ms
5,376 KB |
testcase_08 | AC | 9 ms
5,376 KB |
testcase_09 | AC | 9 ms
5,376 KB |
testcase_10 | AC | 18 ms
5,376 KB |
testcase_11 | AC | 3 ms
5,376 KB |
testcase_12 | AC | 15 ms
5,376 KB |
testcase_13 | AC | 5 ms
5,376 KB |
testcase_14 | AC | 17 ms
5,376 KB |
testcase_15 | AC | 11 ms
5,376 KB |
testcase_16 | AC | 13 ms
5,376 KB |
testcase_17 | AC | 16 ms
5,376 KB |
testcase_18 | AC | 5 ms
5,376 KB |
testcase_19 | AC | 22 ms
5,376 KB |
testcase_20 | AC | 9 ms
5,376 KB |
testcase_21 | AC | 16 ms
5,376 KB |
testcase_22 | AC | 11 ms
5,376 KB |
testcase_23 | AC | 133 ms
5,376 KB |
testcase_24 | AC | 62 ms
5,376 KB |
コンパイルメッセージ
warning: function `mul` is never used --> src/main.rs:24:4 | 24 | fn mul(a: &Vec<Vec<i64>>, b: &Vec<Vec<i64>>, md: i64) -> Vec<Vec<i64>> { | ^^^ | = note: `#[warn(dead_code)]` on by default
ソースコード
use std::collections::HashMap; use std::io::Write; /* ----------------------------------------------- */ fn d(m: usize) -> Vec<usize> { let mut y = m; let mut v = Vec::<usize>::with_capacity(30); for x in 2..(m as f64).sqrt() as usize + 5 { if y % x == 0 { let mut c = 0; while y % x == 0 { y /= x; c += 1; } v.push(c); } } if y > 1 { v.push(1); } return v; } fn mul(a: &Vec<Vec<i64>>, b: &Vec<Vec<i64>>, md: i64) -> Vec<Vec<i64>> { let h = a.len(); let w = b[0].len(); let p = a[0].len(); let mut ret = vec![vec![0; w]; h]; for i in 0..h { for j in 0..w { for k in 0..p { ret[i][j] += (a[i][k] * b[k][j]) % md; if ret[i][j] >= md { ret[i][j] -= md; } } } } return ret; } fn dp(n: usize, x: usize, md: i64) -> i64 { let mut cor = vec![1; x + 1]; for _ in 0..n - 1 { let mut sum = cor.to_vec(); for i in 1..sum.len() { sum[i] += sum[i - 1]; sum[i] %= md; } for i in 0..sum.len() { cor[i] = sum[x - i]; } } return cor.iter().sum::<i64>() % md; } fn run<W: Write>(sc: &mut scanner::Scanner, out: &mut std::io::BufWriter<W>) { let md: i64 = 1000000007; let n: usize = sc.next(); let m: usize = sc.next(); /* let mut mat = vec![vec![0; size]; size]; for i in 0..size { for j in i..size { mat[i][j] = 1; } } let mut val = vec![vec![0; size]; size]; for i in 0..size { val[i][i] = 1; } let mut k = n; while k > 0 { if k & 1 == 1 { val = mul(&val, &mat, md); } mat = mul(&mat, &mat, md); k >>= 1; } println!("{:?}", val); let cor: Vec<i64> = val .into_iter() .reduce(|ac, it| ac.into_iter().zip(it).map(|(a, b)| (a + b) % md).collect()) .unwrap(); */ let mut ans = 1; let mut map = HashMap::<usize, i64>::new(); for x in d(m) { let p = map.entry(x).or_insert(0); if *p == 0 { *p = dp(n, x, md); } ans *= *p; ans %= md; } writeln!(out, "{}", ans).ok(); } /* ----------------------------------------------- */ #[allow(dead_code)] mod scanner { use std::str::FromStr; pub struct Scanner<'a> { it: std::str::SplitWhitespace<'a>, } impl<'a> Scanner<'a> { pub fn new(s: &'a String) -> Scanner<'a> { Scanner { it: s.split_whitespace(), } } pub fn next<T: FromStr>(&mut self) -> T { self.it.next().unwrap().parse::<T>().ok().unwrap() } pub fn next_bytes(&mut self) -> Vec<u8> { self.it.next().unwrap().bytes().collect() } pub fn next_chars(&mut self) -> Vec<char> { self.it.next().unwrap().chars().collect() } pub fn next_vec<T: FromStr>(&mut self, len: usize) -> Vec<T> { (0..len).map(|_| self.next()).collect() } } } /* ----------------------------------------------- */ fn main() { use std::io::Read; let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); let mut sc = scanner::Scanner::new(&s); let out = std::io::stdout(); let mut out = std::io::BufWriter::new(out.lock()); run(&mut sc, &mut out); } /* ----------------------------------------------- */