acwing 1221
作者:
gou都不学
,
2024-02-20 22:44:06
,
所有人可见
,
阅读 43
#include<bits/stdc++.h>
using namespace std;
const int N=1e5;
int n;
struct sum
{
int s,c,d;
bool operator<(const sum &t) const
{
if(s!=t.s) return s<t.s;
if(c!=t.c) return c<t.c;
if(d!=t.d) return d<t.d;
}
}sum[N];
int main()
{
cin>>n;
int m;
for(int c=0;c*c<=n;c++)
{
for(int d=c;c*c+d*d<=n;d++)
{
sum[m++]={c*c+d*d,c,d};
}
}
sort(sum,sum+m);
for(int a=0;a*a<=n;a++)
{
for(int b=a;b*b+a*a<=n;b++)
{
int t=n-a*a-b*b;
int l=0,r=m-1;
while(l<r)
{
int mid=l+r>>1;
if(sum[mid].s>=t) r=mid;
else l=mid+1;
}
if(sum[l].s==t)
{
printf("%d %d %d %d",a,b,sum[l].c,sum[l].d);
return 0;
}
}
}
return 0;
}