結果

問題 No.2249 GCDistance
ユーザー 👑 kakel-sankakel-san
提出日時 2023-03-17 23:01:43
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 1,309 bytes
コンパイル時間 1,542 ms
コンパイル使用メモリ 111,144 KB
実行使用メモリ 108,896 KB
最終ジャッジ日時 2023-10-18 16:02:12
合計ジャッジ時間 8,841 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
102,284 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

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[] NMi => ReadLine().Split().Select(c => int.Parse(c) - 1).ToArray();
    static int[][] NMap(int n) => Enumerable.Repeat(0, n).Select(_ => NMi).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var cache = Enumerable.Repeat(-1L, 10_000_001).ToArray();
        var t = NN;
        var ans = new long[t];
        for (var u = 0; u < t; ++u)
        {
            var n = NN;
            ans[u] = (long)n * (n - 1) - A015614(n, cache);
        }
        WriteLine(string.Join("\n", ans));
    }
    static long A015614(int n, long[] cache)
    {
        if (n == 0) return -1;
        if (cache[n] >= 0) return cache[n];
        var c = 2L;
        var j = 2;
        var k1 = n / j;
        while (k1 > 1)
        {
            var j2 = n / k1 + 1;
            c += (j2 - j) * (2 * A015614(k1, cache) + 1);
            j = j2;
            k1 = n / j2;
        }
        var ans = ((long)n * (n - 1) - c + j) / 2;
        cache[n] = ans;
        return ans;
    }
}
0