結果

問題 No.1809 Divide NCK
ユーザー 👑 kakel-sankakel-san
提出日時 2023-12-21 22:30:13
言語 C#
(.NET 8.0.203)
結果
WA  
実行時間 -
コード長 2,222 bytes
コンパイル時間 6,879 ms
コンパイル使用メモリ 158,448 KB
実行使用メモリ 180,156 KB
最終ジャッジ日時 2023-12-21 22:30:25
合計ジャッジ時間 11,240 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
32,548 KB
testcase_01 AC 75 ms
32,548 KB
testcase_02 AC 75 ms
32,548 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 75 ms
32,548 KB
testcase_08 AC 75 ms
32,548 KB
testcase_09 WA -
testcase_10 AC 77 ms
32,548 KB
testcase_11 AC 79 ms
32,548 KB
testcase_12 AC 77 ms
32,548 KB
testcase_13 AC 75 ms
32,548 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 74 ms
32,548 KB
testcase_17 AC 73 ms
32,548 KB
testcase_18 AC 75 ms
32,548 KB
testcase_19 AC 74 ms
32,548 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 73 ms
32,548 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 74 ms
32,548 KB
testcase_26 WA -
testcase_27 AC 74 ms
32,548 KB
testcase_28 WA -
testcase_29 AC 74 ms
32,548 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 74 ms
32,548 KB
testcase_35 WA -
testcase_36 AC 74 ms
32,548 KB
testcase_37 AC 74 ms
32,548 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (96 ms)。
MSBuild のバージョン 17.7.3+8ec440e68 (.NET)
  main -> /home/judge/data/code/bin/Release/net7.0/main.dll
  main -> /home/judge/data/code/bin/Release/net7.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 long[] NList => ReadLine().Split().Select(long.Parse).ToArray();
    public static void Main()
    {
        Solve();
        // Test();
    }
    static void Test()
    {
        var r = new Random();
        var count = 0;
        while (true)
        {
            var n = r.NextInt64(1_000_000_000_000_000_000) + 1;
            var k = r.NextInt64(Math.Min(1000, n)) + 1;
            var m = r.NextInt64(1_000_000_000_000) + 2;
            // 愚直解
            var s1 = All(n, k, m);
            // 作成解
            var s2 = Divide(n, k, m);
            if (s1 != s2)
            {
                WriteLine($"{n} {k} {m}");
                // WriteLine(string.Join("\n", map.Select(m => string.Join(" ", m))));
                WriteLine(s1);
                WriteLine(s2);
                return;
            }
            ++count;
            if (count % 1000 == 0) WriteLine(count);
        }
    }
    static long All(long n, long k, long m)
    {
        var ans = 0L;
        for (var i = n - k + 1; i <= n; ++i)
        {
            var tmp = i;
            while (tmp % m == 0)
            {
                ++ans;
                tmp /= m;
            }
        }
        for (var i = 1L; i <= k; ++i)
        {
            var tmp = i;
            while (tmp % m == 0)
            {
                --ans;
                tmp /= m;
            }
        }
        return ans;
    }
    static void Solve()
    {
        var c = NList;
        var (n, k, m) = (c[0], c[1], c[2]);
        WriteLine(Divide(n, k, m));
    }
    static long Divide(long n, long k, long m)
    {
        return Divs(n, m) - Divs(n - k, m) - Divs(k, m);
    }
    static long Divs(long n, long p)
    {
        if (n < 0) return 0;
        var prev = 1L;
        var ans = 0L;
        while (true)
        {
            var pc = prev * p;
            if (pc / p != prev) break;
            ans += n / pc;
            prev = pc;
        }
        return ans;
    }
}
0