結果

問題 No.1383 Numbers of Product
ユーザー sten_sansten_san
提出日時 2021-02-09 01:32:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,979 bytes
コンパイル時間 2,645 ms
コンパイル使用メモリ 206,684 KB
実行使用メモリ 43,160 KB
最終ジャッジ日時 2023-09-20 10:24:09
合計ジャッジ時間 8,294 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 WA -
testcase_06 AC 1 ms
4,376 KB
testcase_07 WA -
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

struct uns_t {} uns;
template <typename Element, typename Head, typename ...Args>
auto vec(Element init, Head arg, Args ...args) {
    if constexpr (sizeof...(Args) == 0) return std::vector(arg, init);
    else return std::vector(arg, vec(init, args...));
}
template <typename Element, typename Head, typename ...Args>
auto vec(uns_t, Head arg, Args ...args) {
    return vec(Element(), arg, args...);
}

int main() {
    using int128_t = __int128;

    int64_t n, k, m; cin >> n >> k >> m;

    auto pow = [&](auto a, auto b) {
        int128_t ans = 1;
        while (b--) {
            ans *= a;
        }
        return ans;
    };

    auto prod = [&](auto a, auto b) {
        int128_t ans = a;
        for (int i = 1; i <= b; ++i) {
            ans *= a + i * k;
        }
        return ans;
    };

    auto sqrt = [&](auto x) {
        auto left = 0, right = x;
        while (1 < right - left) {
            auto mid = left + (right - left) / 2;
            if (mid * mid <= x) {
                left = mid;
            }
            else {
                right = mid;
            }
        }
        return left;
    };

    auto included = [&](auto x) {
        auto a = __int128(k);
        auto square = a * a + 4 * x;
        auto root = sqrt(square);
        if (root * root != square || (root - a) % 2) return false;
        return true;
    };

    map<int64_t, int> count;
    for (int b = 2; b < 20; ++b) {
        for (int a = 1; prod(a, b) <= n; ++a) {
            ++count[prod(a, b)];
        }
    }

    if (m == 1) {
        int64_t ans = 0;
        for (auto [a, b] : count) {
            ans -= included(a);
        }
        ans += (sqrt(int128_t(k) * k + 4 * n) - k) / 2;

        cout << ans << endl;
        return 0;
    }

    for (auto &[a, b] : count) {
        b += included(a);
    }

    int ans = 0;
    for (auto [a, b] : count) {
        ans += b == m;
    }

    cout << ans << endl;
}

0