結果

問題 No.3332 Consecutive Power Sum (Small)
コンテスト
ユーザー Vi24E
提出日時 2025-10-01 16:24:16
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,430 bytes
コンパイル時間 1,907 ms
コンパイル使用メモリ 204,216 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-11-02 21:11:49
合計ジャッジ時間 3,836 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 2
other WA * 52
権限があれば一括ダウンロードができます

ソースコード

diff #

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

vector<array<ll, 3>> ans;

__int128_t power(ll x, int e){
    __int128_t t = 1;
    for (int i = 0; i < e; i++) t *= x;
    return t;
}

void solve(ll n, int e) {
    ll l = 1, r = 1;
    __int128_t t = 1;
    while (power(r, e) <= n){
        if (t == n){
            ans.push_back({e, l, r});
        }
        if (t <= n) {
            r++;
            t += power(r, e);
        }
        else {
            t -= power(l, e);
            l++;
        }
    }
    return;
}

__int128_t square_sum(ll x){
	return (__int128_t)x * (x + 1) * (2 * x + 1) / 6;
}

void solve2(ll n) {
    for (ll w = 1; w * w * w <= 3 * n; w++){
    	auto check = [&](ll mid)->bool {
		    return square_sum(mid + w - 1) - square_sum(mid - 1) <= n;
		};
		ll ok = 0, ng = 1<<30;
		if (square_sum(ok + w - 1) - square_sum(ok - 1) > n) continue;
		while (abs(ok - ng) > 1){
		    ll mid = (ok + ng) / 2;
		    if (check(mid)) ok = mid;
		    else ng = mid;
		}
		if (square_sum(ok + w - 1) - square_sum(ok - 1) == n) ans.push_back({2, ok, ok + w - 1});
    }
}

int main(){
    ll n;
    cin >> n;
    assert(1 <= n && n <= 1000000000000000000);

    solve2(n);
    for (int i = 3; i < 60; i++){
        solve(n, i);
    }
    
    sort(ans.begin(), ans.end());
    cout << ans.size() << "\n";
    for (auto [e, l, r] : ans){
        cout << e << " " << l << " " << r << '\n';
    }
}
0