結果

問題 No.847 Divisors of Power
ユーザー NoiriNoiri
提出日時 2019-07-23 08:39:04
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,180 bytes
コンパイル時間 1,725 ms
コンパイル使用メモリ 168,180 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-16 09:35:16
合計ジャッジ時間 2,525 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 1 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,944 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,940 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 2 ms
6,944 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,944 KB
testcase_28 AC 2 ms
6,940 KB
testcase_29 AC 1 ms
6,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

// 素因数分解(first要素がfactで、second要素がその個数)
vector<pair<ll, ll>> prime_factorize(ll n) {
    vector<pair<ll, ll>> res;
    for (ll p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

vector<P> fact;
int ans = 0;
ll m;

void dfs(int n, ll sum){
    if(fact.size() == n) return;
    if(sum > m) return;
    dfs(n+1, sum);
    rep(i, fact[n].second){
        sum *= fact[n].first;
        //cout << "s = " << sum << endl;
        if(sum > m) break;
        if(sum <= m) ans++;
        dfs(n+1, sum);
    }
}


int main(){
    ll n, k;
    cin >> n >> k >> m;

    fact = prime_factorize(n);

    rep(i, fact.size()){
        fact[i].second *= k;
    }

    /*
    for(auto p: fact){
        cout << "fact: " << p.first << ", N: " << p.second << endl;
    }
    */

    dfs(0, 1);
    cout << ans+1 << endl;
}
0