結果

問題 No.1809 Divide NCK
ユーザー SSRS
提出日時 2022-01-14 21:27:00
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 753 bytes
コンパイル時間 1,852 ms
コンパイル使用メモリ 171,740 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-20 07:48:51
合計ジャッジ時間 2,966 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long INF = 3000000000000000000;
long long f(long long a, long long b){
  long long ans = 0;
  while (a > 0){
    a /= b;
    ans += a;
  }
  return ans;
}
int main(){
  long long N, K, M;
  cin >> N >> K >> M;
  vector<pair<long long, int>> P;
  for (long long i = 2; i * i <= M; i++){
    if (M % i == 0){
      int cnt = 0;
      while (M % i == 0){
        M /= i;
        cnt++;
      }
      P.push_back(make_pair(i, cnt));
    }
  }
  if (M > 1){
    P.push_back(make_pair(M, 1));
  }
  int cnt = P.size();
  long long ans = INF;
  for (int i = 0; i < cnt; i++){
    long long p = P[i].first;
    ans = min(ans, (f(N, p) - f(K, p) - f(N - K, p)) / P[i].second);
  }
  cout << ans << endl;
}
0