結果

問題 No.1809 Divide NCK
ユーザー trineutron
提出日時 2022-01-14 21:38:28
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 3 ms / 2,000 ms
+ 560µs
コード長 639 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,494 ms
コンパイル使用メモリ 343,508 KB
実行使用メモリ 9,876 KB
最終ジャッジ日時 2026-11-08 10:01:24
合計ジャッジ時間 4,588 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

int64_t count(int64_t n, int64_t p)
{
    if (n == 0)
    {
        return 0;
    }
    return n / p + count(n / p, p);
}

int main()
{
    int64_t n, k, m;
    cin >> n >> k >> m;
    map<int64_t, int64_t> primes;
    for (int64_t i = 2; i * i <= m; i++)
    {
        while (m % i == 0)
        {
            primes[i]++;
            m /= i;
        }
    }
    if (m > 1)
    {
        primes[m]++;
    }
    int64_t ans = 1e9;
    for (auto &&[p, c] : primes)
    {
        ans = min(ans, (count(n, p) - count(k, p) - count(n - k, p)) / c);
    }
    cout << ans << endl;
    return 0;
}
0