http://poj.org/problem?id=2100
2.Idea
Two Pointers
3.Source
ll S;
ll s, t;
int n = 10000000;
vector<int> ans1, ans2;
void solve()
{
int res = 0;
ll s = 0, t = 0;
ll sum = 0;
for (;;) {
while (t < n && sum < S) {
sum += t*t; t++;
}
if (sum < S) break;
if (sum == S) {
if (s == 0) s++;
ans1.push_back(s);
ans2.push_back(t - 1);
}
sum -= s*s;
s++;
}
printf("%d\n", ans1.size());
for (int i = 0; i < ans1.size(); i++) {
printf("%d", ans2[i] - ans1[i] + 1);
for (int j = ans1[i]; j <= ans2[i]; j++) printf(" %d", j);
printf("\n");
}
}
int main()
{
scanf("%lld", &S);
n = sqrt(1.0 * S) + 1;
solve();
return 0;
}
No comments:
Post a Comment