http://acm.hdu.edu.cn/showproblem.php?pid=2058
1-n the number of consecutive fields and equals M.
Assuming that the length from I begins with a field of k and equal to M, then (i+ i+k-1) * k/2=m ie (2*i+k-1) *k==2m then from k<= sqrt (2*m);
i=m/k-(k-1)/2. This is done by the length of the enumeration k from large to small, and simultaneously computes the value of I and whether it is equal to M, the output can be.
Note that from the (2*i+k-1) *k==2m This is the K<=SQRT (2*m) Instead of I, this is to facilitate the calculation, and from large to small enumeration k, but also to ensure that the output is sequentially output.
1#include <stdio.h>2#include <math.h>3 intMain ()4 {5 intn,m,l,k;6 while(SCANF ("%d%d", &n,&m)!=eof&&n| |m)7 {8L= (int) sqrt (Double(2*m));9 while(L)Ten { Onek=m/l-(l1)/2; A if(K*l+l* (l1)/2==m) -printf"[%d,%d]\n", k,k+l-1); -l--; the } -printf"\ n"); - } - return 0; +}
hdu-2058 the sum problem (math problem)