結果
問題 |
No.2829 GCD Divination
|
ユーザー |
|
提出日時 | 2024-08-02 21:58:50 |
言語 | C# (.NET 8.0.404) |
結果 |
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 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 3 TLE * 2 -- * 30 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /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/
ソースコード
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); } }