题解:AT_abc420_g [ABC420G] sqrt(n²+n+X)
前言
个人认为比 F 简单,就是个初中数学题。
做法
首先我们把开方去掉。假设
再化简得到:
把
其中
有人可能担心
复杂度为
代码
赛时代码如下。另附提交记录。
#include<bits/stdc++.h>
#define int long long
#define R(x) x=read()
using namespace std;
inline int read() {
int x=0,y=1;
char e=getchar();
while(e<'0'||e>'9') {
if(e=='-')y=-1;
e=getchar();
}
while(e>='0'&&e<='9') {
x=(x<<1)+(x<<3)+(e^'0');
e=getchar();
}
return x*y;
}
const int N=10000000;
int x;
int tot,ans[100000];
signed main() {
R(x);
int c=4*x-1;
for(int i=1; i*i<=abs(c); ++i) {
if(c%i==0) {
int j=c/i;
if((i+j)%4==0) {
ans[++tot]=((i-j)/2-1)/2;
}
int ii=-i,jj=-j;
if((ii+jj)%4==0) {
ans[++tot]=((ii-jj)/2-1)/2;
}
}
}
sort(ans+1,ans+1+tot);
cout<<tot<<"\n";
for(int i=1; i<=tot; ++i)cout<<ans[i]<<" ";
return 0;
}
```cpp