結果
| 問題 |
No.2380 Sylow P-subgroup
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-07-14 23:09:09 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 28 ms / 2,000 ms |
| コード長 | 1,103 bytes |
| コンパイル時間 | 872 ms |
| コンパイル使用メモリ | 113,548 KB |
| 実行使用メモリ | 27,276 KB |
| 最終ジャッジ日時 | 2024-09-16 08:17:01 |
| 合計ジャッジ時間 | 2,273 ms |
|
ジャッジサーバーID (参考情報) |
judge6 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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);
}
}