結果

問題 No.2380 Sylow P-subgroup
ユーザー 👑 kakel-sankakel-san
提出日時 2023-07-14 23:09:09
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 1,103 bytes
コンパイル時間 1,776 ms
コンパイル使用メモリ 69,784 KB
実行使用メモリ 23,932 KB
最終ジャッジ日時 2023-10-14 13:34:32
合計ジャッジ時間 3,633 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
23,932 KB
testcase_01 AC 59 ms
23,820 KB
testcase_02 AC 59 ms
23,836 KB
testcase_03 AC 58 ms
21,816 KB
testcase_04 AC 59 ms
21,772 KB
testcase_05 AC 59 ms
21,904 KB
testcase_06 AC 59 ms
23,904 KB
testcase_07 AC 59 ms
23,888 KB
testcase_08 AC 59 ms
21,804 KB
testcase_09 AC 57 ms
21,988 KB
testcase_10 AC 59 ms
23,832 KB
testcase_11 AC 60 ms
23,920 KB
testcase_12 AC 59 ms
19,936 KB
testcase_13 AC 60 ms
21,892 KB
testcase_14 AC 59 ms
21,848 KB
testcase_15 AC 59 ms
21,872 KB
testcase_16 AC 60 ms
21,852 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static long NN => long.Parse(ReadLine());
    static long[] NList => ReadLine().Split().Select(long.Parse).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var c = NList;
        var (n, p) = (c[0], c[1]);
        WriteLine(Psub(n, p));
    }
    static long Psub(long n, long p)
    {
        var mul = 0L;
        var tmp = p;
        var mod = 998_244_353;
        checked {
        while (true)
        {
            if (tmp > n) break;
            // mul = (mul + n / tmp) % mod;
            mul += n / tmp;
            tmp *= p;
        }
        }
        return Exp((int)p, (int)(mul % (mod - 1)), mod);
    }
    static long Exp(int n, int 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