結果

問題 No.2326 Factorial to the Power of Factorial to the...
ユーザー ecto0310
提出日時 2023-05-28 15:12:18
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 678 bytes
コンパイル時間 1,781 ms
コンパイル使用メモリ 192,760 KB
最終ジャッジ日時 2025-02-13 12:41:09
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using i64 = int64_t;

const i64 MOD = 1e9 + 7;

int main() {
  i64 N, P;
  cin >> N >> P;
  i64 count = 0;
  i64 prd = 1;
  for (i64 i = 1; i <= N; i++) {
    i64 t = i;
    while (0 < t && t % P == 0) {
      t /= P;
      count++;
      count %= MOD;
    }
    prd *= i;
    prd %= MOD;
  }
  auto p = [](i64 x, i64 n) {
    i64 ret = 1;
    while (0 < n) {
      if (n % 2 == 1) {
        ret *= x;
        ret %= MOD;
      }
      x *= x;
      x %= MOD;
      n >>= 1;
    }
    return ret;
  };
  ;
  for (i64 i = 1; i <= N; i++) {
    prd = p(prd, i);
    prd %= MOD;
  }
  cout << count * prd % MOD << endl;
  return 0;
}
0