1.b^3 - a^3 = c(zy)
zy说要卡nlogn的,然而他实际给的组数只有100组,然后因为在windows下随机的,所以给出的 c <= 100000。然后只要胆子大。。。。
通过打表发现,x^3-(x-1)^3 <= 1e9, x的最大值是18258
然后我们用一个数组去记录 2^3-1^3, 3^3-2^3, 4^3-3^3, ...., 18258^3-18257^3
对于c, 用尺取去判断就好了
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int UP = 18258 + 10; vector<ll> ss; int c; int main () { for (ll i=2; i<UP; ++i) { ss.emplace_back(i*i*i-(i-1)*(i-1)*(i-1)); } freopen("1.in","r",stdin); freopen("11.out","w",stdout); while (~ scanf("%d", &c)) { ll sum = 0; deque<int> q; bool flag = false; for (int i=0; i<UP; ++i) { q.push_back(i); sum += ss[i]; while (!q.empty() && sum>c) { sum -= ss[q.front()]; q.pop_front(); } if (sum==c) { flag = true; printf ("%d %d\n", q.front()+1, q.back()+2); break; } } if (!flag) puts("-1"); } return 0; }