1 条题解

  • 1
    @ 2024-12-20 20:20:42

    注意到 $\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;
    }
    
    • 1

    信息

    ID
    62
    时间
    2000ms
    内存
    256MiB
    难度
    2
    标签
    递交数
    2
    已通过
    2
    上传者