結果
問題 | No.1514 Squared Matching |
ユーザー |
|
提出日時 | 2022-12-01 21:31:09 |
言語 | Rust (1.83.0 + proconio) |
結果 |
MLE
|
実行時間 | - |
コード長 | 838 bytes |
コンパイル時間 | 19,605 ms |
コンパイル使用メモリ | 378,372 KB |
実行使用メモリ | 783,196 KB |
最終ジャッジ日時 | 2024-10-09 02:16:10 |
合計ジャッジ時間 | 69,593 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 MLE * 16 |
ソースコード
fn get_factors(n: usize) -> Vec<usize> { let mut flgs = vec![true; n+1]; flgs[0] = false; flgs[1] = false; let mut ret = (0..=n).collect::<Vec<_>>(); for i in 2..=n { if !flgs[i] { continue; } let base = i * i; for j in i..=n/i { let idx = i*j; flgs[idx] = false; while ret[idx] % base == 0 { ret[idx] /= base; } } } ret } fn main() { let mut n = String::new(); std::io::stdin().read_line(&mut n).ok(); let n: usize = n.trim().parse().unwrap(); let factors = get_factors(n); let mut cnts = vec![0usize; n+1]; for &v in factors.iter() { cnts[v] += 1; } let mut result = 0usize; for a in 1..=n { result += cnts[factors[a]]; } println!("{}", result); }