結果

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

ソースコード

diff #

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  /**
   * N!中にPの因数が k 個含まれている
   * ans = k * (N!^{N!})
  */
  long long mod {1000000007};
  long long n, p;
  cin >> n >> p;

  long long k {};
  for (long long ct {p}; ct <= n; ct *= p) {
    k += n / ct;
    k %= mod;
  }
  long long n_fac {1};
  for (long long i=1;i<=n;++i) {
    n_fac *= i;
    n_fac %= mod;
  }
  //cout << "fac[i]:" << n_fac << '\n';
  long long n_fac_pow {n_fac};
  long long ans {1};
  for (long long c = n_fac; c != 0; c>>=1) {
    if (c & 1) ans *= n_fac_pow;
    n_fac_pow *= n_fac_pow;

    ans %= mod;
    n_fac_pow %= mod;
  }
  ans *= k;
  ans %= mod;
  cout << ans << '\n';
}
0