Math problems. Tossing the day, this method is not the best, but in accordance with their own first instinct of the method of AC is very happy.
#include <stdio.h>#include<string.h>#include<math.h>#include<algorithm>using namespacestd;structabc{intstart, end;} dt[5000000];BOOLcmpConstAbc&a,Constabc&b) { if(A.start = = B.start)returnA.end <B.end; returnA.start <B.start;}intMain () {intN, M, I; while(~SCANF ("%d%d", &n, &m)) {if(n = =0&& m = =0) Break; intSumm =0; intyy = sqrt (1.0*L); if(Yy*yy < m) yy++; for(i = yy; I >=1; i--) { if(m%i = =0) { intUU =i; intHH = m/i; if(UU = =1) { if(M <=N) {Dt[summ].start=hh; Dt[summ].end=hh; Summ++; } if(HH-1) %2==0) { intx = (HH-1) /2; if(x >=1&& x <= n&&x +1>=1&& x +1<=N) {Dt[summ].start=x; Dt[summ].end= x +1; Summ++; } } } Else if(UU! =1) { if(UU%2==1) { intShu = UU/2; if(Hh-shu >=1&& Hh-shu <= n&&hh + Shu >=1&& hh + Shu <=N) {Dt[summ].start= HH-Shu; Dt[summ].end= hh +Shu; Summ++; } } if(HH%2==1) { intxx = hh/2; if(Xx-uu +1>=1&& Xx-uu +1<= n&&xx + uu >=1&& xx + uu <=N) {Dt[summ].start= Xx-uu +1; Dt[summ].end= xx +UU; Summ++; }}} UU= m/i; HH =i; if(UU = =1) { if(M <=N) {Dt[summ].start=hh; Dt[summ].end=hh; Summ++; } if(HH-1) %2==0) { intx = (HH-1) /2; if(x >=1&& x <= n&&x +1>=1&& x +1<=N) {Dt[summ].start=x; Dt[summ].end= x +1; Summ++; } } } Else if(UU! =1) { if(UU%2==1) { intShu = UU/2; if(Hh-shu >=1&& Hh-shu <= n&&hh + Shu >=1&& hh + Shu <=N) {Dt[summ].start= HH-Shu; Dt[summ].end= hh +Shu; Summ++; } } if(HH%2==1) { intxx = hh/2; if(Xx-uu +1>=1&& Xx-uu +1<= n&&xx + uu >=1&& xx + uu <=N) {Dt[summ].start= Xx-uu +1; Dt[summ].end= xx +UU; Summ++; }}}}} sort (dt, DT+Summ, CMP); for(i =0; i < Summ; i++) { if(i = =0) printf ("[%d,%d]\n", Dt[i].start, dt[i].end); Else if(i>0) { if(Dt[i].start! = dt[i-1].start | | Dt[i].end! = dt[i-1].end) printf ("[%d,%d]\n", Dt[i].start, dt[i].end); }} printf ("\ n"); } return 0;}
HDU 2058The sum problem