The sum problem
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 9078 Accepted Submission(s): 2776
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <queue>
#include <vector>
#include <cmath>
#define lson l,m,k<<1
#define rson m+1,r,k<<1|1
#define N 20000
using namespace std;
int main()
{
int n,m;
int len,a;
while(scanf("%d%d",&n,&m),n||m)
{
len=sqrt(double(2*m))+1;
while(--len)
{
a=m/len-(len-1)/2;
if((((a<<1)+len-1)*len>>1)==m)
a<=n?printf("[%d,%d]\n",a,a+len-1):0;
}
printf("\n");
}
return 0;
}
//下面错误的代码也过了、、呵呵
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <queue>
#include <vector>
#include <cmath>
#define lson l,m,k<<1
#define rson m+1,r,k<<1|1
#define N 20000
using namespace std;
int main()
{
int n,m;
int len,a;
while(scanf("%d%d",&n,&m),n||m)
{
len=sqrt(double(2*m))+1;
while(--len)
{
a=m/len-(len-1)/2;
if((((a<<1)+len-1)*len>>1)==m)
printf("[%d,%d]\n",a,a+len-1);//这里没判断a要不大于n噢
}
printf("\n");
}
return 0;
}