結果

問題 No.2326 Factorial to the Power of Factorial to the...
ユーザー KoseTKoseT
提出日時 2023-05-28 15:27:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 711 bytes
コンパイル時間 2,130 ms
コンパイル使用メモリ 197,600 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-27 12:11:43
合計ジャッジ時間 2,948 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 WA -
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 1 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 2 ms
4,380 KB
testcase_15 WA -
testcase_16 AC 2 ms
4,376 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 2 ms
4,380 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;

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

  long long k {};
  long long ct {p};
  for (long long ct {p}; ct <= n; ct *= ct) {
    k += n / ct;
  }
  long long mod {1000000007};
  long long n_fac {1};
  for (long long i=1;i<=n;++i) {
    n_fac *= i;
    n_fac %= mod;
  }
  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