ZJNU 1129 - The sum problem——中级

枚举区间可能的长度len,将m减去1~len构成的序列和后如果结果是len的倍数,则可以构成答案区间。

 1 /*
 2 Written By. StelaYuri
 3 */
 4 #include<stdio.h>
 5 #include<math.h>
 6 int main(){
 7     int n,m,len,b;
 8     while(scanf("%d%d",&n,&m)!=EOF&&(n||m)){
 9         for(len=sqrt(m*2);len;len--){
10                 b=m-(len*len+len)/2;
11                 if(b%len==0)
12                     printf("[%d,%d]\n",(b/len)+1,(b/len)+len);
13         }
14         putchar('\n');
15     }
16     return 0;
17 }

猜你喜欢

转载自www.cnblogs.com/stelayuri/p/12213253.html