結果

問題 No.847 Divisors of Power
ユーザー どららどらら
提出日時 2019-07-06 01:15:06
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,395 bytes
コンパイル時間 1,840 ms
コンパイル使用メモリ 176,388 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-16 08:19:19
合計ジャッジ時間 2,603 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, n) for (int i = (a); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define FOR(it, c) \
    for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

map<ll, ll> factorize(ll x) {
    map<ll, ll> ret;
    ll d, q;
    while (x >= 4 && x % 2 == 0) {
        ret[2]++;
        x /= 2;
    }
    d = 3;
    q = x / d;
    while (q >= d) {
        if (x % d == 0) {
            ret[d]++;
            x = q;
        } else {
            d += 2;
        }
        q = x / d;
    }
    ret[x]++;
    return ret;
}

ll ret;

void solve(ll M, ll now, int idx, const vector<pair<ll, ll>>& fv) {
    if (idx >= fv.size()) {
        if (now <= M)
            ret++;
        return;
    }
    ll p = fv[idx].first;
    ll k = fv[idx].second;

    int kk = 0;
    while (kk <= k && now <= M) {
        solve(M, now, idx + 1, fv);
        kk++;
        now *= p;
    }
}

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

    if (N == 1) {
        cout << 1 << endl;
        return 0;
    }

    map<ll, ll> fact = factorize(N);
    vector<pair<ll, ll>> fv;
    for (const auto& p : fact) fv.emplace_back(p.first, p.second * K);
    reverse(ALLOF(fv));

    ret = 0;
    solve(M, 1, 0, fv);
    cout << ret << endl;

    return 0;
}
0