結果
問題 | No.1514 Squared Matching |
ユーザー | phspls |
提出日時 | 2022-12-01 21:34:10 |
言語 | Rust (1.77.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 877 bytes |
コンパイル時間 | 2,301 ms |
コンパイル使用メモリ | 154,112 KB |
実行使用メモリ | 588,260 KB |
最終ジャッジ日時 | 2024-04-17 09:19:40 |
合計ジャッジ時間 | 40,517 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | MLE | - |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 1 ms
6,940 KB |
testcase_04 | AC | 1 ms
6,944 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 18 ms
11,228 KB |
testcase_07 | AC | 348 ms
114,032 KB |
testcase_08 | MLE | - |
testcase_09 | AC | 1,821 ms
495,916 KB |
testcase_10 | MLE | - |
testcase_11 | MLE | - |
testcase_12 | MLE | - |
testcase_13 | MLE | - |
testcase_14 | MLE | - |
testcase_15 | MLE | - |
testcase_16 | MLE | - |
testcase_17 | MLE | - |
testcase_18 | MLE | - |
testcase_19 | MLE | - |
testcase_20 | MLE | - |
testcase_21 | MLE | - |
testcase_22 | AC | 350 ms
119,392 KB |
testcase_23 | AC | 781 ms
236,572 KB |
testcase_24 | AC | 1,178 ms
353,764 KB |
testcase_25 | AC | 1,611 ms
470,968 KB |
ソースコード
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 as f64).sqrt().ceil() as usize { 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![0u32; n+1]; for &v in factors.iter() { cnts[v] += 1; } let mut result = 0usize; for a in 1..=n { result += cnts[factors[a]] as usize; } println!("{}", result); }