题解:AT_abc420_g [ABC420G] sqrt(n²+n+X)
ABC 420 G - sqrt(n²+n+X)
题目大意
给定整数
题目标签
- 数学
题解
设
可以证明
时间复杂度:
额外空间复杂度:
参考代码
#include <bits/stdc++.h>
using namespace std;
const int K = 15000000;
long long x;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> x;
vector<long long> v;
for (int i = -K; i <= K; i++)
if ((x - 1LL * i * i) % (i * 2 - 1) == 0)
v.push_back((x - 1LL * i * i) / (i * 2 - 1));
sort(begin(v), end(v));
v.erase(unique(begin(v), end(v)), end(v));
cout << v.size() << '\n';
for (size_t i = 0; i < v.size(); i++)
cout << v[i] << "\n "[i + 1 < v.size()];
return 0;
}
整场比赛题解:AtCoder Beginner Contest 420 题解 (A~E & G)。