結果

問題 No.3332 Consecutive Power Sum (Small)
コンテスト
ユーザー himueu
提出日時 2026-10-29 01:12:04
言語 C++23(gcc16)
(gcc 16.2.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc16.so -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,661 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,909 ms
コンパイル使用メモリ 186,468 KB
実行使用メモリ 13,612 KB
最終ジャッジ日時 2026-10-29 01:12:15
合計ジャッジ時間 7,501 ms
ジャッジサーバーID
(参考情報)
judge7_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 16 WA * 36
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <algorithm>
#include <iostream>
#include <tuple>
#include <vector>

std::vector<long long> divisors(long long n) {
    std::vector<long long> res;
    for (long long i = 1; i <= n / i; i++) {
        if (n % i > 0) { continue; }
        res.push_back(i);
    }
    std::reverse(res.begin(), res.end());
    return res;
}

void solve() {
    using namespace std;
    long long n;
    cin >> n;

    auto pow = [&](long long x, int k, long long lim) -> long long {
        long long res = 1;
        for (int _ = 0; _ < k; _++) {
            if (res > lim / x) { return -1; }
            res *= x;
        }
        return res;
    };

    vector<tuple<int, int, int>> ans;
    // e = 1
    for (auto d : divisors(n * 2)) {
        long long e = n * 2 / d;
        if (d > e) { break; }
        if ((e - d) % 2 == 0) { continue; }
        long long l = (e - d - 1) / 2;
        long long r = l + d;
        ans.emplace_back(1, l + 1, r);
    }
    // e > 1
    for (int e = 2; e < 40; e++) {
        vector<long long> acc = {0};
        for (long long i = 1; ; i++) {
            long long p = pow(i, e, n);
            if (p == -1) { break; }
            acc.push_back(acc.back() + p);
        }
        int sz = acc.size();
        for (long long l = 0; l < sz; l++) {
            long long r = lower_bound(acc.begin(), acc.end(), acc[l] + n) - acc.begin();
            if (acc[l] + n == acc[r]) { ans.emplace_back(e, l + 1, r); }
        }
    }
    cout << ans.size() << "\n";
    for (auto [e, l, r] : ans) { cout << e << " " << l << " " << r << "\n"; }
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    solve();
}
0