結果

問題 No.2326 Factorial to the Power of Factorial to the...
ユーザー rurunrurun
提出日時 2023-05-28 14:25:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 560 bytes
コンパイル時間 1,910 ms
コンパイル使用メモリ 199,808 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-08 05:23:38
合計ジャッジ時間 2,728 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 WA -
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 WA -
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 WA -
testcase_14 AC 2 ms
5,376 KB
testcase_15 WA -
testcase_16 AC 2 ms
5,376 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using lint = long long;

lint modpow(lint a, lint b, lint mod = 1e9+7) {
  lint ans = 1, now = a;
  for (int i = 0; i < 60; i++) {
    if (b&(1LL<<i)) ans *= now;
    now *= now;
    ans %= mod, now %= mod;
  }
  return ans;
}

int main() {
  lint n, p;
  cin >> n >> p;
  lint cnt = 0;
  lint power = 1;
  lint MOD = 1e9+7;
  for (lint i = 1; i <= n; i++) {
    lint x = i;
    power*=i;
    power%=MOD;
    while (x%p == 0) cnt++, x/=p;
  }
  lint num = modpow(power, power);
  cout << (num*cnt)%MOD << endl;

}
0