結果

問題 No.847 Divisors of Power
ユーザー yuji9511yuji9511
提出日時 2019-07-05 22:29:56
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 450 ms / 2,000 ms
コード長 3,452 bytes
コンパイル時間 1,861 ms
コンパイル使用メモリ 179,424 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-16 07:46:48
合計ジャッジ時間 3,852 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
inline vector<ll> divisor(ll M){ //約数の全列挙
    vector<ll> dd;
    for(ll i = 1; i*i <= M; i++){
        if(M % i == 0){
            dd.push_back(i);
            if(i * i != M){
                dd.push_back(M/i);
            }
        }
    }
    sort(dd.begin(), dd.end());
    return dd;
}
inline vector<ll> factor(ll M){ //素因数分解
    vector<ll> dd;
    if(M == 1){
        dd.push_back(1);
        return dd;
    }
    for(ll i = 2; i*i <= M; i++){
        while(M % i == 0){
            dd.push_back(i);
            M /= i;
        }
    }
    if(M != 1) dd.push_back(M);
    sort(dd.begin(), dd.end());
    return dd;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,K,M;
    ll num = 30;
    cin >> N >> K >> M;
    if(N == 1){
        print(1);
        return 0;
    }
    vector<ll> fac = factor(N);
    // printa(fac, fac.size());
    map<ll,ll> mp;
    bool flg = false;
    for(auto &e: fac){
        mp[e]++;
        if(e == 2) flg = true;
    }
    for(auto &e: mp){
        ll v = e.second * K;
        if(v > num){
            mp[e.first] = num;
        }else{
            mp[e.first] *= K;
        }
    }
    vector<lpair> lp;
    for(auto &e: mp){
        lp.push_back(make_pair(e.first, e.second));
    }
    sort(lp.begin(), lp.end());
    ll sz = mp.size() / 2;
    vector<ll> ans;
    rep(bit,0,pow(num, sz)){
        ll v[20] = {};
        ll b = bit;
        ll idx = 0;
        while(b){
            v[idx] = b % num;
            b /= num;
            idx++;
        }
        bool ok = true;
        rep(i,0,sz){
            if(v[i] > lp[i].second) ok = false;
        }
        if(not ok) continue;
        ll tt = 1;
        rep(i,0,sz){
            tt *= pow(lp[i].first, v[i]);
            if(tt > 1e9 || tt > M){
                ok = false;
                break;
            }
        }
        if(not ok) continue;
        ans.push_back(tt);
    }
    sort(ans.begin(), ans.end());

    vector<ll> ans2;
    num = 20;
    ll sz2 = mp.size() - sz;
    // print(sz2);
    rep(bit,0,pow(num, sz2)){
        ll v[20] = {};
        ll b = bit;
        ll idx = 0;
        while(b){
            v[idx] = b % num;
            b /= num;
            idx++;
        }
        bool ok = true;
        rep(i,0,sz2){
            if(v[i] > lp[sz+i].second) ok = false;
        }
        if(not ok) continue;
        ll tt = 1;
        rep(i,0,sz2){
            if(pow(lp[sz+i].first, v[i]) > 1e9){
                ok = false;
                break;
            }
            tt *= pow(lp[sz+i].first, v[i]);
            if(tt > 1e9 || tt > M){
                ok = false;
                break;
            }
        }
        if(not ok) continue;
        ans2.push_back(tt);
    }
    sort(ans2.begin(), ans2.end());
    // printa(ans, ans.size());
    // printa(ans2, ans2.size());
    ll val = 0;
    rep(i,0,ans.size()){
        ll k = M / ans[i];
        ll pos = upper_bound(ans2.begin(), ans2.end(), k) - ans2.begin();
        val += pos;
    }
    print(val);





}
0