結果

問題 No.2829 GCD Divination
ユーザー naut3naut3
提出日時 2024-08-02 22:38:31
言語 Rust
(1.77.0)
結果
TLE  
実行時間 -
コード長 761 bytes
コンパイル時間 12,974 ms
コンパイル使用メモリ 383,536 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-08-02 22:39:05
合計ジャッジ時間 18,441 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
10,752 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1,592 ms
5,376 KB
testcase_03 AC 0 ms
5,376 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(non_snake_case)]
#[allow(unused_imports)]
use proconio::{fastout, input, marker::*};

#[fastout]
fn main() {
    input! {
        N: usize,
    }

    let mut buffer = vec![0.0; 10_000_010];

    solve(N, &mut buffer);

    println!("{}", buffer[N]);
}

fn solve(m: usize, buffer: &mut [f64]) {
    if m == 1 {
        return;
    }

    let mut w = 0.;

    for i in 1..m {
        let g = gcd(i, m);

        if buffer[g] == 0. && g != 1 {
            solve(g, buffer);
        }

        w += buffer[g];
    }

    buffer[m] = w / (m - 1) as f64 + m as f64 / (m - 1) as f64;
}

fn gcd(a: usize, b: usize) -> usize {
    if a < b {
        return gcd(b, a);
    }

    if b == 0 {
        return a;
    } else {
        return gcd(b, a % b);
    }
}
0