結果

問題 No.2326 Factorial to the Power of Factorial to the...
ユーザー 👑 kakel-sankakel-san
提出日時 2023-10-11 00:20:36
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 67 ms / 2,000 ms
コード長 1,380 bytes
コンパイル時間 3,074 ms
コンパイル使用メモリ 63,760 KB
実行使用メモリ 24,476 KB
最終ジャッジ日時 2023-10-11 00:29:29
合計ジャッジ時間 3,842 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
21,808 KB
testcase_01 AC 67 ms
22,860 KB
testcase_02 AC 63 ms
21,856 KB
testcase_03 AC 66 ms
24,412 KB
testcase_04 AC 64 ms
24,048 KB
testcase_05 AC 63 ms
23,840 KB
testcase_06 AC 64 ms
22,360 KB
testcase_07 AC 66 ms
22,584 KB
testcase_08 AC 67 ms
22,656 KB
testcase_09 AC 67 ms
22,720 KB
testcase_10 AC 63 ms
23,824 KB
testcase_11 AC 61 ms
21,792 KB
testcase_12 AC 61 ms
21,812 KB
testcase_13 AC 63 ms
21,948 KB
testcase_14 AC 67 ms
24,476 KB
testcase_15 AC 61 ms
21,780 KB
testcase_16 AC 61 ms
23,816 KB
testcase_17 AC 66 ms
22,464 KB
testcase_18 AC 63 ms
21,856 KB
testcase_19 AC 61 ms
21,684 KB
testcase_20 AC 61 ms
21,820 KB
testcase_21 AC 62 ms
23,788 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 long[n + 1];
        f1[1] = 1;
        for (var i = 2; i < f1.Length; ++i) f1[i] = f1[i - 1] * i % mod;
        var f2 = new long[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