結果

問題 No.1383 Numbers of Product
ユーザー MisterMister
提出日時 2021-02-07 21:14:41
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,776 ms / 2,000 ms
コード長 1,383 bytes
コンパイル時間 818 ms
コンパイル使用メモリ 83,016 KB
実行使用メモリ 68,392 KB
最終ジャッジ日時 2023-08-14 22:11:01
合計ジャッジ時間 46,592 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,500 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1,057 ms
43,144 KB
testcase_08 AC 1,027 ms
42,652 KB
testcase_09 AC 1,282 ms
52,204 KB
testcase_10 AC 1,729 ms
67,804 KB
testcase_11 AC 1,704 ms
66,768 KB
testcase_12 AC 1,725 ms
67,248 KB
testcase_13 AC 1,696 ms
64,700 KB
testcase_14 AC 1,383 ms
55,200 KB
testcase_15 AC 1,102 ms
45,404 KB
testcase_16 AC 1,704 ms
66,952 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 20 ms
4,376 KB
testcase_29 AC 1,326 ms
53,268 KB
testcase_30 AC 1,735 ms
68,296 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 331 ms
16,680 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 1,585 ms
62,492 KB
testcase_36 AC 1,513 ms
59,892 KB
testcase_37 AC 1,776 ms
68,116 KB
testcase_38 AC 1,749 ms
68,292 KB
testcase_39 AC 1,744 ms
68,392 KB
testcase_40 AC 1,757 ms
68,176 KB
testcase_41 AC 1,744 ms
68,324 KB
testcase_42 AC 1,748 ms
68,180 KB
testcase_43 AC 1,748 ms
68,264 KB
testcase_44 AC 1,743 ms
68,184 KB
testcase_45 AC 1,751 ms
68,196 KB
testcase_46 AC 2 ms
4,376 KB
testcase_47 AC 1,706 ms
66,668 KB
testcase_48 AC 1,710 ms
67,168 KB
testcase_49 AC 1,743 ms
67,900 KB
testcase_50 AC 1,737 ms
67,740 KB
testcase_51 AC 1 ms
4,380 KB
testcase_52 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 1 "main.cpp"
#include <iostream>
#include <map>

using namespace std;
using lint = long long;

constexpr lint INF = 1LL << 60;

lint prod(lint a, lint b) {
    if (a == 0 || b == 0) return 0;
    if (a >= INF / b + 1) return INF;
    return min(INF, a * b);
}

void solve() {
    lint n, k, m;
    cin >> n >> k >> m;

    auto g = [&](lint a, lint b) {
        auto ret = a;
        for (lint x = 1; x <= b; ++x) {
            ret = prod(ret, a + prod(k, x));
        }
        return ret;
    };

    map<lint, int> cnt;
    for (lint b = 2; b <= 18; ++b) {
        for (lint a = 1;; ++a) {
            auto p = g(a, b);
            if (p > n) break;

            if (!cnt.count(p)) cnt[p] = 0;
            ++cnt[p];
        }
    }

    auto h = [&](lint x) {
        lint ok = 0, ng = INF;
        while (ng - ok > 1) {
            lint a = (ok + ng) / 2;

            if (g(a, 1) <= x) {
                ok = a;
            } else {
                ng = a;
            }
        }
        return ok;
    };

    lint ones = h(n);
    for (auto& [x, c] : cnt) {
        if (g(h(x), 1) == x) {
            ++c;
            --ones;
        }
    }

    lint ans = (m == 1 ? ones : 0);
    for (auto [x, c] : cnt) {
        if (c == m) ++ans;
    }
    cout << ans << "\n";
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    solve();

    return 0;
}
0