维护一个滑动窗口即可
注意不能有m到m的区间,因为区间长度要大于1
#include#define _for(i, a, b) for(int i = (a); i <= (b); i++)using namespace std;int main(){ int m, sum = 0, st = 1; scanf("%d", &m); _for(i, 1, m - 1) { sum += i; if(sum > m) while(sum > m) sum -= st, st++; if(sum == m) printf("%d %d\n", st, i); } return 0;}