注意到 $\displaystyle \sum_{i=x}^{y}i=\dfrac{(x+y)(y-x+1)}{2}$,其中 x+y>yx+1x+y>y-x+1

枚举 yx+1=2,3,,2Ny-x+1=2,3,\ldots,\sqrt{2N} 并逐个检验即可。

#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long n;
    cin >> n;
    n *= 2;
    int w = sqrtl(n + 0.1);
    for (int i = 2; i <= w; i++)
        if (n % i == 0)
        {
            if (i % 2 == 0 && n / i % 2 == 0) continue;
            cout << (n / i - i + 1) / 2 << ' ' << (n / i + i - 1) / 2 << endl;
        }
    return 0;
}