結果

問題 No.847 Divisors of Power
ユーザー finefine
提出日時 2019-07-05 22:08:25
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 432 ms / 2,000 ms
コード長 1,236 bytes
コンパイル時間 2,042 ms
コンパイル使用メモリ 191,224 KB
実行使用メモリ 33,104 KB
最終ジャッジ日時 2024-10-06 21:50:56
合計ジャッジ時間 3,826 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using P = pair<ll, vector<ll> >;

map<ll, ll> prime_factor(ll n) {
    map<ll, ll> res;
    for (ll i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            ++res[i];
            n /= i;
        }
    }
    if (n != 1) res[n] = 1;
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, K, m;
    cin >> n >> K >> m;

    map<ll, ll> p = prime_factor(n);
    vector<ll> v, lim;
    for (auto& pp : p) {
        pp.second *= K;
        v.push_back(pp.first);
        lim.push_back(pp.second);
    }

    priority_queue<P, vector<P>, greater<P> > pq; 
    pq.emplace(1, vector<ll>(v.size(), 0));
    set<ll> s;
    while (!pq.empty()) {
        P tar = pq.top();
        pq.pop();
        if (tar.first > m) break;
        if (s.find(tar.first) != s.end()) continue;
        s.insert(tar.first);
        for (int i = 0; i < v.size(); i++) {
            if (tar.second[i] >= lim[i]) continue;
            ll val = tar.first * v[i];
            if (val > m) continue;
            vector<ll> cnt(tar.second);
            cnt[i]++;
            pq.emplace(val, cnt);
        }
    }
    cout << s.size() << "\n";
    return 0;
}
0