結果
| 問題 |
No.3332 Consecutive Power Sum (Small)
|
| コンテスト | |
| ユーザー |
ococonomy1
|
| 提出日時 | 2025-11-02 21:46:05 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 5,050 bytes |
| コンパイル時間 | 2,140 ms |
| コンパイル使用メモリ | 203,860 KB |
| 実行使用メモリ | 814,672 KB |
| 最終ジャッジ日時 | 2025-11-02 21:46:31 |
| 合計ジャッジ時間 | 3,991 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 5 MLE * 1 -- * 46 |
ソースコード
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll = __int128_t;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pli = pair<ll,int>;
#define MOD 998244353
//#define MOD 1000000007
#define el '\n'
#define El '\n'
#define YESNO(x) ((x) ? "Yes" : "No")
#define YES YESNO(true)
#define NO YESNO(false)
#define EXIT_ANS(x) {cout << (x) << '\n'; return;}
template <typename T> void inline SORT(vector<T> &v){sort(v.begin(),v.end()); return;}
template <typename T> void inline REV(vector<T> &v){reverse(v.begin(),v.end()); return;}
template <typename T> void inline VEC_UNIQ(vector<T> &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end()); return;}
template <typename T> T inline MAX(vector<T> &v){return *max_element(v.begin(),v.end());}
template <typename T> T inline MIN(vector<T> &v){return *min_element(v.begin(),v.end());}
template <typename T> T inline SUM(vector<T> &v){T ans = 0; for(int i = 0; i < (int)v.size(); i++)ans += v[i]; return ans;}
template <typename T> void inline DEC(vector<T> &v){for(int i = 0; i < (int)v.size(); i++)v[i]--; return;}
template <typename T> void inline INC(vector<T> &v){for(int i = 0; i < (int)v.size(); i++)v[i]++; return;}
void inline TEST(void){cerr << "TEST" << endl; return;}
template <typename T> bool inline chmin(T &x,T y){
if(x > y){
x = y;
return true;
}
return false;
}
template <typename T> bool inline chmax(T &x,T y){
if(x < y){
x = y;
return true;
}
return false;
}
// floor(sqrt(x))を整数で返す。にぶたんしているが幅が定数なので計算時間はO(1) にぶたん内で重い動作もない(代入、掛け算、ビットシフト、大小比較だけ)
long long ococo_floor_lsqrt(long long x) {
// この仕様で嬉しいか?
if(x < 0) {
return -1;
}
if(x < INT_MAX / 2) {
int ix = x;
if(x == 0) return 0;
if(x < 4) return 1;
if(x < 9) return 2;
int l = std::sqrt((double)x) - 2, r = std::sqrt((double)x) + 2;
for(int i = l; i <= r + 1; i++) {
if(i * i > ix) return i - 1;
}
return r + 1;
}
// doubleの仮数部が52bitでlong longが64bitだから差が12bitのため、誤差が2**12=4096を超えないんじゃないかと思ってこの範囲でにぶたんをしているが、
// 全然これは嘘かもしれないので、めちゃくちゃ要検証である。
// 一旦±10で見てダメそうだったら5000広げる方向性にした。これ以上の高速化が必要なパターンはあんまないだろうしこれでええやろ
// とりあえずこのにぶたんは、sqrt(x)の答えが[l,r]のどこかにあるものとしている
long long l = std::sqrt((double)x) - 10, r = std::sqrt((double)x) + 10;
if(l * l > x) l -= 5000;
if(r * r < x) r += 5000;
if(l * l > x) l -= 5000 * 5000;
if(r * r < x) r += 5000 * 5000;
if(l * l > x) l -= 5000LL * 5000LL * 5000LL;
if(r * r < x) r += 5000LL * 5000LL * 5000LL;
while(r - l >= 2) {
long long c = (r + l) >> 1;
if(c * c <= x) l = c;
else r = c;
}
for(long long i = l; i <= r + 1; i++) {
if(i * i > x) return i - 1;
}
return r + 1;
}
vector<pii> func(ll n,int x){
vector<ll> v;
v.push_back(0LL);
for(int i = 1; true; i++){
ll temp = 1;
for(int j = 0; j < x; j++)temp *= (ll)i;
if(temp > n)break;
v.push_back(v.back() + temp);
}
vector<pii> ans;
for(int i = 0; i < (int)v.size(); i++){
ll val = n + v[i];
if(!binary_search(v.begin(),v.end(),val))continue;
int idx = lower_bound(v.begin(),v.end(),val) - v.begin();
ans.push_back(pair(i + 1,idx));
}
return ans;
}
#define MULTI_TEST_CASE false
void solve(void){
//問題を見たらまず「この問題設定から言えること」をいっぱい言う
//よりシンプルな問題に言い換えられたら、言い換えた先の問題を自然言語ではっきりと書く
//複数の解法のアイデアを思いついた時は全部メモしておく
//g++ -D_GLIBCXX_DEBUG -Wall -O2 a.cpp -o o
long long temp; cin >> temp;
ll n = temp;
vector<array<int,3>> ans;
for(int i = 1; i <= 40; i++){
vector<pii> temp = func(n,i);
for(int j = 0; j < (int)temp.size(); j++){
ans.push_back({i,temp[j].first,temp[j].second});
}
}
cout << (int)ans.size() << el;
for(int i = 0; i < (int)ans.size(); i++){
cout << (long long)ans[i][0] << ' ';
cout << (long long)ans[i][1] << ' ';
cout << (long long)ans[i][2] << el;
}
return;
}
void calc(void){
return;
}
signed main(void){
cin.tie(nullptr);
ios::sync_with_stdio(false);
calc();
int t = 1;
if(MULTI_TEST_CASE)cin >> t;
while(t--){
solve();
}
return 0;
}
ococonomy1