結果

問題 No.1383 Numbers of Product
ユーザー milanis48663220milanis48663220
提出日時 2021-07-01 22:52:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,358 bytes
コンパイル時間 2,149 ms
コンパイル使用メモリ 125,484 KB
実行使用メモリ 68,456 KB
最終ジャッジ日時 2023-09-10 20:43:56
合計ジャッジ時間 24,484 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 483 ms
43,096 KB
testcase_08 AC 567 ms
42,592 KB
testcase_09 AC 594 ms
51,960 KB
testcase_10 AC 799 ms
67,560 KB
testcase_11 AC 787 ms
66,560 KB
testcase_12 AC 808 ms
67,312 KB
testcase_13 AC 913 ms
64,776 KB
testcase_14 AC 637 ms
55,276 KB
testcase_15 AC 506 ms
45,396 KB
testcase_16 AC 788 ms
66,824 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 WA -
testcase_21 AC 2 ms
4,376 KB
testcase_22 WA -
testcase_23 AC 2 ms
4,376 KB
testcase_24 WA -
testcase_25 AC 1 ms
4,376 KB
testcase_26 WA -
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 8 ms
4,376 KB
testcase_29 AC 613 ms
53,368 KB
testcase_30 AC 811 ms
68,144 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 146 ms
16,760 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 736 ms
62,532 KB
testcase_36 AC 833 ms
59,944 KB
testcase_37 AC 974 ms
68,308 KB
testcase_38 AC 815 ms
68,192 KB
testcase_39 AC 815 ms
68,240 KB
testcase_40 AC 804 ms
68,208 KB
testcase_41 AC 969 ms
68,204 KB
testcase_42 AC 821 ms
68,188 KB
testcase_43 AC 968 ms
68,456 KB
testcase_44 AC 818 ms
68,268 KB
testcase_45 AC 818 ms
68,192 KB
testcase_46 AC 2 ms
4,376 KB
testcase_47 AC 779 ms
66,800 KB
testcase_48 AC 799 ms
67,252 KB
testcase_49 AC 810 ms
68,092 KB
testcase_50 AC 961 ms
67,844 KB
testcase_51 WA -
testcase_52 WA -
権限があれば一括ダウンロードができます

ソースコード

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++){
        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(c*(c+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