結果

問題 No.1809 Divide NCK
ユーザー miscalcmiscalc
提出日時 2022-01-14 21:44:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,451 bytes
コンパイル時間 2,211 ms
コンパイル使用メモリ 206,468 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-30 13:51:08
合計ジャッジ時間 2,784 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,812 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 11 ms
6,940 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 11 ms
6,944 KB
testcase_19 AC 11 ms
6,944 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 1 ms
6,940 KB
testcase_24 AC 1 ms
6,944 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 1 ms
6,940 KB
testcase_28 AC 1 ms
6,940 KB
testcase_29 AC 7 ms
6,944 KB
testcase_30 AC 1 ms
6,940 KB
testcase_31 AC 2 ms
6,944 KB
testcase_32 WA -
testcase_33 AC 2 ms
6,940 KB
testcase_34 AC 1 ms
6,940 KB
testcase_35 AC 1 ms
6,940 KB
testcase_36 AC 1 ms
6,940 KB
testcase_37 AC 1 ms
6,944 KB
testcase_38 AC 2 ms
6,944 KB
testcase_39 AC 1 ms
6,944 KB
testcase_40 AC 1 ms
6,940 KB
testcase_41 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/modint>
using namespace atcoder;
using mint = modint998244353;
//using mint = modint1000000007;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using tlll = tuple<ll, ll, ll>;
constexpr ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll safemod(ll A, ll M) {return (A % M + M) % M;}
ll divfloor(ll A, ll B) {if (B < 0) {return divfloor(-A, -B);} return (A - safemod(A, B)) / B;}
ll divceil(ll A, ll B) {if (B < 0) {return divceil(-A, -B);} return divfloor(A + B - 1, B);}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

vector<pll> factorize(ll n)
{
  vector<pll> ret;
  for (ll p = 2; p * p <= n; p++)
  {
    ll e = 0;
    while (n % p == 0)
    {
      n /= p;
      e++;
    }
    if (e > 0)
      ret.push_back(make_pair(p, e));
  }
  if (n > 1)
    ret.push_back(make_pair(n, 1));
  return ret;
}

ll f(ll n, ll p) // n! は p で何回割り切れるか
{
  ll ret = 0;
  for (ll k = p; k <= n; k *= p)
  {
    ret += n / k;
  }
  return ret;
}

int main()
{
  ll N, K, M;
  cin >> N >> K >> M;

  auto PE = factorize(M);

  ll ans = INF;
  for (auto &[p, e] : PE)
  {
    ll e2 = f(N, p) - f(N - K, p) - f(K, p);
    ll tmp = e2 / e;
    chmin(ans, tmp);
  }
  cout << ans << endl;
}
0