結果

問題 No.2326 Factorial to the Power of Factorial to the...
ユーザー rurunrurun
提出日時 2023-05-28 14:42:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 575 bytes
コンパイル時間 2,063 ms
コンパイル使用メモリ 197,656 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-27 10:26:40
合計ジャッジ時間 3,050 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

lint MOD = 1000000007;

lint modpow(lint a, lint b, lint mod) {
  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;
  for (lint i = 1; i <= n; i++) {
    lint x = i;
    power*=i;
    power%=MOD;
    while (x%p == 0) cnt++, x/=p;
  }
  cnt %= MOD;
  lint num = modpow(power, power, MOD);
  cout << (num*cnt)%MOD << endl;

}
0