結果
| 問題 |
No.3332 Consecutive Power Sum (Small)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-10-01 16:29:07 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,414 bytes |
| コンパイル時間 | 2,022 ms |
| コンパイル使用メモリ | 203,700 KB |
| 実行使用メモリ | 7,724 KB |
| 最終ジャッジ日時 | 2025-11-02 21:12:01 |
| 合計ジャッジ時間 | 3,822 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 2 |
| other | WA * 52 |
コンパイルメッセージ
main.cpp: In function ‘void solve(ll, int)’:
main.cpp:18:28: warning: narrowing conversion of ‘e’ from ‘int’ to ‘long long unsigned int’ [-Wnarrowing]
18 | ans.push_back({e, l, r});
| ^
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = unsigned 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;
}
ll square_sum(ll x){
return 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 (ng - ok > 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';
}
}