1 条题解

  • 0
    @ 2025-9-4 21:59:20

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

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

    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        ios::sync_with_stdio(0);
        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
    27
    时间
    1000ms
    内存
    256MiB
    难度
    2
    标签
    递交数
    5
    已通过
    3
    上传者