- P27's solution
P27's Solution
- 2025-9-4 21:59:20 @
注意到 $\displaystyle \sum_{i=x}^{y}i=\dfrac{(x+y)(y-x+1)}{2}$,其中 。
枚举 并逐个检验即可。
#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;
}