結果

問題 No.847 Divisors of Power
ユーザー tactac
提出日時 2019-07-09 00:02:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 1,495 bytes
コンパイル時間 1,565 ms
コンパイル使用メモリ 171,160 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-07-29 01:28:39
合計ジャッジ時間 3,118 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define out(a) cout << a << endl
#define SZ(v) (int)v.size()


using pil = vector<pair<int, ll> >;
vector<pair<int, ll> > prime_factorize(int n) {
    int tmp = n;
    vector<pair<int, ll> > v;
    for (int i = 2; i * i <= n; ++i) {
        ll cnt = 0;
        while (tmp % i == 0) {
            tmp /= i;
            cnt++;
        }
        if (cnt) v.eb(i, cnt);
    }
    if (tmp != 1) v.eb(tmp, 1);
    return v;
}
int n, k, m;
int dfs(pil v, int dep, ll product) {
    if (dep == SZ(v)) return 1;
    //その素因数を何個とるか
    int res = 0;
    rep(i, v[dep].S + 1) {
        ll tmp = product * pow(v[dep].F, i);
        //out(dep << " " << product << " " << tmp);
        if (tmp > m) break;
        res += dfs(v, dep + 1, tmp);
        
    }
    return res;
}
int main() {
    cin >> n >> k >> m;
    pil v = prime_factorize(n);
    //rep(i, SZ(v)) out(v[i].F << " " << v[i].S);
    rep(i, SZ(v)) v[i].S *= k;
    //rep(i, SZ(v)) out(v[i].F << " " << v[i].S);
    out(dfs(v, 0, 1));
}

/*
 M ≤ 10^9
 
 N
 2 * 3 * 5 * ... * 23
 2^9
 
 2^3 * 3^3 * 5^3 * 7^3
 4^4 = 2^8
 
 枝刈りすれば計算量大丈夫そう?
 
 */
0