結果
問題 | No.2829 GCD Divination |
ユーザー | naut3 |
提出日時 | 2024-08-02 23:17:59 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,282 bytes |
コンパイル時間 | 14,840 ms |
コンパイル使用メモリ | 402,204 KB |
実行使用メモリ | 522,856 KB |
最終ジャッジ日時 | 2024-08-02 23:19:02 |
合計ジャッジ時間 | 59,981 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 485 ms
392,452 KB |
testcase_01 | AC | 394 ms
340,348 KB |
testcase_02 | AC | 1,760 ms
275,448 KB |
testcase_03 | AC | 487 ms
392,528 KB |
testcase_04 | WA | - |
testcase_05 | MLE | - |
testcase_06 | MLE | - |
testcase_07 | MLE | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | AC | 1,440 ms
240,832 KB |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | AC | 944 ms
392,564 KB |
testcase_21 | WA | - |
testcase_22 | AC | 1,652 ms
253,836 KB |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | AC | 1,481 ms
286,088 KB |
testcase_32 | AC | 1,617 ms
303,184 KB |
testcase_33 | WA | - |
testcase_34 | WA | - |
ソースコード
#![allow(non_snake_case)] #[allow(unused_imports)] use proconio::{fastout, input, marker::*}; #[fastout] fn main() { input! { N: u32, } let mut sieve = vec![vec![]; 10_000_010]; for p in 2u32..=10_000_000 { if sieve[p as usize].is_empty() && gcd(p, N) != 1 { for q in (p * 2..10_000_010).step_by(p as usize) { sieve[q as usize].push(p); } } } let mut dp = vec![0.; 10_000_010]; for k in 2u32..=N { let mut s = 0.; for &d in sieve[k as usize].iter() { if sieve[k as usize].len() == 1 { s += dp[d as usize]; } else if d == sieve[k as usize][0] { let m = sieve[k as usize][1]; s += dp[d as usize] * (m - 1) as f32; } else { let m = sieve[k as usize][0]; s += dp[d as usize] * (m - 1) as f32; } } dp[k as usize] = s; dp[k as usize] /= (k - 1) as f32; dp[k as usize] += (k) as f32 / (k - 1) as f32; } println!("{}", dp[N as usize]); } fn gcd(a: u32, b: u32) -> u32 { if a < b { return gcd(b, a); } if b == 0 { return a; } else { return gcd(b, a % b); } }