結果

問題 No.2829 GCD Divination
ユーザー 👑 kakel-sankakel-san
提出日時 2024-08-02 21:58:50
言語 C#
(.NET 8.0.203)
結果
TLE  
実行時間 -
コード長 1,085 bytes
コンパイル時間 8,130 ms
コンパイル使用メモリ 166,048 KB
実行使用メモリ 115,900 KB
最終ジャッジ日時 2024-08-02 21:59:04
合計ジャッジ時間 13,923 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
33,408 KB
testcase_01 AC 45 ms
37,280 KB
testcase_02 TLE -
testcase_03 AC 48 ms
29,696 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 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (92 ms)。
MSBuild のバージョン 17.9.6+a4ecab324 (.NET)
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var n = NN;
        var dp = Enumerable.Repeat(-1.0, n + 1).ToArray();
        WriteLine(DFS(n, dp));
    }
    static double DFS(int a, double[] dp)
    {
        if (dp[a] >= 0) return dp[a];
        if (a == 1)
        {
            dp[a] = 0;
            return dp[a];
        }
        var sum = 0.0;
        for (var i = 1; i < a; ++i)
        {
            sum += DFS(GCD(a, i), dp);
        }
        dp[a] = (sum / a + 1) * a / (a - 1);
        return dp[a];
    }
    static int GCD(int a, int b)
    {
        if (a < b) return GCD(b, a);
        if (a % b == 0) return b;
        return GCD(b, a % b);
    }
}
0