結果

問題 No.1383 Numbers of Product
ユーザー milanis48663220milanis48663220
提出日時 2021-07-01 22:54:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,447 ms / 2,000 ms
コード長 2,399 bytes
コンパイル時間 2,161 ms
コンパイル使用メモリ 127,432 KB
実行使用メモリ 68,264 KB
最終ジャッジ日時 2023-09-10 20:46:29
合計ジャッジ時間 32,869 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 629 ms
43,096 KB
testcase_08 AC 853 ms
42,644 KB
testcase_09 AC 777 ms
52,012 KB
testcase_10 AC 1,041 ms
67,528 KB
testcase_11 AC 1,024 ms
66,632 KB
testcase_12 AC 1,040 ms
67,288 KB
testcase_13 AC 1,363 ms
64,776 KB
testcase_14 AC 830 ms
55,336 KB
testcase_15 AC 665 ms
45,496 KB
testcase_16 AC 1,038 ms
66,796 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 12 ms
4,456 KB
testcase_29 AC 794 ms
53,224 KB
testcase_30 AC 1,049 ms
68,232 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 195 ms
16,748 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 954 ms
62,480 KB
testcase_36 AC 1,249 ms
59,960 KB
testcase_37 AC 1,440 ms
68,264 KB
testcase_38 AC 1,050 ms
68,260 KB
testcase_39 AC 1,052 ms
68,248 KB
testcase_40 AC 1,051 ms
68,168 KB
testcase_41 AC 1,447 ms
68,172 KB
testcase_42 AC 1,052 ms
68,248 KB
testcase_43 AC 1,439 ms
68,248 KB
testcase_44 AC 1,053 ms
68,248 KB
testcase_45 AC 1,057 ms
68,244 KB
testcase_46 AC 2 ms
4,376 KB
testcase_47 AC 1,019 ms
66,716 KB
testcase_48 AC 1,033 ms
67,196 KB
testcase_49 AC 1,050 ms
68,032 KB
testcase_50 AC 1,435 ms
67,836 KB
testcase_51 AC 1 ms
4,380 KB
testcase_52 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

const ll INF = 2e18;

ll calc(ll a, ll b, ll k){
    ll ans = a;
    for(ll i = 1; i <= b; i++){
        if(k >= INF/i) return INF;
        ll x = a+k*i;
        if(ans >= INF/x) return INF;
        ans *= x;
    }
    // cout << "calc(" << a << "," << b << "," << k << ") = " << ans << endl;
    return ans;
}

ll f(ll x, ll k){
    ll l = 0, r = 1e9;
    while(r-l > 1){
        ll c = (l+r)/2;
        if(calc(c, 1, k) > x) r = c;
        else l = c;
    }
    return l;
}

int naive(ll n, ll k, ll m){
    map<ll, int> cnt;
    for(int b = 1; ; b++){
        if(calc(1, b, k) > n) break;
        for(int a = 1; ; a++){
            ll x = calc(a, b, k);
            if(x > n) break;
            if(cnt.count(x) == 0) cnt[x] = 1;
            else cnt[x]++;
        }
    }
    int ans = 0;
    for(auto [_, c]: cnt){
        if(c == m) ans++;
    }
    return ans;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    ll n, k, m; cin >> n >> k >> m;
    map<ll, int> cnt;
    for(int b = 2; ; b++){
        if(calc(1, b, k) > n) break;
        for(int a = 1; ; a++){
            ll x = calc(a, b, k);
            if(x > n) break;
            if(cnt.count(x) == 0) cnt[x] = 1;
            else cnt[x]++;
        }
    }
    vector<ll> v;
    for(auto &[x, c]: cnt) {
        ll y = f(x, k);
        if(calc(y, 1, k) == x){
            v.push_back(x);
            c++;
        }
    }
    int ans = 0;
    for(auto [_, c]: cnt){
        if(c == m) ans++;
    }
    if(m == 1){
        ll y = f(n, k);
        ans += y;
        for(auto [x, c]: cnt){
            ll y = f(x, k);
            if(calc(y, 1, k)  == x) ans--;
        }
    }
    cout << ans << endl;
    // cout << naive(n, k, m) << endl;
}
0