結果

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

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int not_prime[1000001];

map<ll, ll> factorize(ll n){
    map<ll, ll> ret;
    ll i = 2;
    not_prime[2] = 0;
    fill(not_prime, not_prime+1000001, 0);
    while(n != 1 && i <= 1000000){
        if(not_prime[i]){
            ++i;
            continue;
        }
        ll j = i;
        while(j <= 1000000){
            not_prime[j] = 1;
            j += i;
        }

        while(n % i == 0){
            n /= i;
            ++ret[i];
        }

        ++i;
    }
    if(n != 1LL){
        ++ret[n];
    }
    return ret;
}

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

    map<ll, ll> mp = factorize(n);

    vector<ll> divisors(1, 1);
    for(auto itr=mp.begin();itr!=mp.end();++itr) {
        ll f = itr->first;
        ll nf = (itr->second) * k;
        int nd = divisors.size();
        for(int i=0;i<nd;++i) {
            ll d = divisors[i];
            for(int j=1;j<=nf;++j) {
                d *= f;
                if(d > m) break;
                divisors.push_back(d);
            }
        }
    }

    cout << divisors.size() << endl;
}
0