TAG 数论
与1209. Sequence Sum Possibi 类似,我是用那道题改的。
#include <stdio.h> #include <math.h> #include <algorithm> using namespace std; struct node { int a,b; }; int T; int n,m; int counter; node ans[1000]; bool cmp( const node &x, const node &y) { if ( x.a!=y.a ) { return x.a<y.a; } return x.b<y.b; } void cal() { counter=-1; for (int i=0; i<=int( sqrt(2.0)*sqrt(m+0.0) ); ++i) { if ( (2*m)%(i+1)==0 && (2*m/(i+1)-i) >=2 && (2*m/(i+1)-i)%2==0 ) { int start=2*m/(i+1)-i; start/=2; if ( i+start<=n ) { ++counter; ans[ counter ].a=start; ans[ counter ].b=start+i; } } } } int main(int argc, char *argv[]) { scanf("%d%d", &n, &m); cal(); sort( ans, ans+counter+1,cmp ); for (int i=0; i<=counter; ++i) { printf("[%d,%d]/n", ans[i].a, ans[i].b ); } return 0; }