题意:找到某一个区间使得区间内的数的平方和等于某一给定值k。
要用到双重pair,书写的格式得注意
思路和poj2739基本一样
注意:是降序输出答案,题目是英文的就没看到
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string.h>
#include<iostream>
#define LL long long
#define INF 0x3f3f3f3f;
using namespace std;
typedef pair<LL, pair<LL, LL> > p;
p ans[1010];
LL n, sum = 0;
int num = 0;
int main()
{
while(~scanf("%I64d", &n) )
{
LL st = 1, en = 1;
sum = 0; num = 0;
while(1){
while(sum + en * en <= n) sum += en * en, en++;
if(sum == n) ans[++num] = p(en - st, pair<LL, LL>(st, en - 1) );
sum -= st * st;
st++;
if(en * en > n) break;
}
printf("%d\n", num);
for(int j = 1; j <= num; j++){
printf("%I64d ", ans[j].first);
for(LL i = ans[j].second.first; i <= ans[j].second.second; i++)
printf("%I64d ", i);
puts("");
}
}
return 0;
}