結果

問題 No.2326 Factorial to the Power of Factorial to the...
ユーザー 👑 kakel-sankakel-san
提出日時 2023-10-11 00:17:54
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,378 bytes
コンパイル時間 3,543 ms
コンパイル使用メモリ 68,020 KB
実行使用メモリ 24,056 KB
最終ジャッジ日時 2023-10-11 00:18:38
合計ジャッジ時間 4,919 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
21,844 KB
testcase_01 WA -
testcase_02 AC 62 ms
21,768 KB
testcase_03 AC 63 ms
23,828 KB
testcase_04 WA -
testcase_05 AC 63 ms
21,820 KB
testcase_06 AC 63 ms
21,780 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 62 ms
21,716 KB
testcase_11 AC 63 ms
21,692 KB
testcase_12 AC 61 ms
23,800 KB
testcase_13 WA -
testcase_14 AC 64 ms
21,792 KB
testcase_15 WA -
testcase_16 AC 62 ms
23,800 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 61 ms
21,820 KB
testcase_20 AC 61 ms
23,640 KB
testcase_21 AC 61 ms
21,696 KB
権限があれば一括ダウンロードができます

ソースコード

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 c = NList;
        var (n, p) = (c[0], c[1]);
        var mod = 1_000_000_007;

        var f1 = new int[n + 1];
        f1[1] = 1;
        for (var i = 2; i < f1.Length; ++i) f1[i] = f1[i - 1] * i % mod;
        var f2 = new int[n + 1];
        f2[1] = 1;
        for (var i = 2; i < f2.Length; ++i) f2[i] = f2[i - 1] * i % (mod - 1);

        var cnt = Exp(f1[n], f2[n], mod);
        var mul = 0;
        for (var i = 1; i <= n; ++i)
        {
            var tmp = i;
            while (tmp % p == 0)
            {
                ++mul;
                tmp /= p;
            }
        }
        WriteLine(cnt * mul % mod);
    }
    static long Exp(long n, long k, int mod)
    {
        if (k == 0) return 1;
        if (k == 1) return n % mod;
        var half = Exp(n, k / 2, mod);
        var result = (half * half) % mod;
        return ((k % 2) == 0) ? result : ((result * n) % mod);
    }
}
0