結果

問題 No.1809 Divide NCK
ユーザー Arfan ArifArfan Arif
提出日時 2023-10-16 06:59:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 962 bytes
コンパイル時間 2,346 ms
コンパイル使用メモリ 202,088 KB
実行使用メモリ 7,852 KB
最終ジャッジ日時 2023-10-16 06:59:13
合計ジャッジ時間 6,867 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

vector<pair<int, int>> prime_factors(ll n) {
    vector<pair<int, int>> pf;
    int p = 2;
    while (p * p <= n) {
        int cnt = 0;
        while (n % p == 0) {
            cnt++;
            n /= p;
        }
        if (cnt) pf.push_back(make_pair(p, cnt));
        if (p == 2) p++;
        else p += 2;
    }
    if (n > 1) pf.push_back(make_pair(n, 1));
    return pf;
}
int find_x(ll N, ll R, pair<int, int>& p) {
    ll C = N - R;
    ll cnt = 0;
    while (N) {
        N /= p.first;
        cnt += N;
    }
    while (C) {
        C /= p.first;
        cnt -= C;
    }
    while (R) {
        R /= p.first;
        cnt -= R;
    }
    return cnt / p.second;
}
int main() {
    ll N, R, M;
    cin >> N >> R >> M;
    vector<pair<int, int>> pf = prime_factors(M);
    int ans = 1e9;
    for (auto& p : pf) {
        ans = min(ans, find_x(N, R, p));
    }
    cout << ans << endl;
}
0