等差数列的运用。Sn = (a1+an) * n / 2 = (a1 + a1 + (n - 1) * d)*n/2。
解题公式变形:(a+a+len)*(len+1)/2 = m => a = m/(len+1)-len/2 (公式直观看上去有点难看懂,建议大家写到纸上再看)
其中m是已知条件,len的最大值为√(2*m)
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int m, n;
while (~scanf("%d %d", &n, &m) && n&&m)
{
int a, len;
len = (int)sqrt(2 * m);
while (len--)
{
a = m / (len + 1) - len / 2;
if ((2 * a + len)*(len + 1) / 2 == m)
{
printf("[%d,%d]\n", a, a + len);
}
}
printf("\n");
}
return 0;
}