拉格朗日定理
根号n为枚举的条件
d从c开始循环(防止重复计算平方和)
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=5e6+9;
int n;
int C[N],D[N];
int main()
{
cin>>n;
memset(C,-1,sizeof C);
for(int c=0;c*c<=n;c++)
for(int d=c;c*c+d*d<=n;d++)
{
int s=c*c+d*d;
if(C[s]==-1)
{
C[s]=c,D[s]=d;//表示平方和为s的时候c和d的值
//并且是最小字典序
}
}
for(int a=0;a*a<=n;a++)
for(int b=a;a*a+b*b<=n;b++)
{
int s=n-a*a-b*b;
if(C[s]!=-1)
{
printf("%d %d %d %d",a,b,C[s],D[s]);
return 0;
}
}
return 0;
}