AcWing 1221. 四平方和
原题链接
简单
作者:
MyPower
,
2023-03-30 21:21:26
,
所有人可见
,
阅读 159
#include <iostream>
#include <cmath>
#define x first
#define y second
using namespace std;
const int N = 5000010;
typedef pair <int, int> PII;
PII logs[N];
int main()
{
int n;
scanf("%d", &n);
for(int c = 0; c <= sqrt(n); c++)
for(int d = c; c * c + d * d <= n; d++)
{
int t = c * c + d * d;
if(logs[t].x) continue;
logs[c * c + d * d].x++;
logs[c * c + d * d].y = c;
}
for(int a = 0; a <= sqrt(n); a++)
for(int b = a; a * a + b * b <= n; b++)
{
int t = n - a * a - b * b;
if(logs[t].x)
{
int c = logs[t].y;
int d = sqrt(t - c * c);
printf("%d %d %d %d", a, b, c, d);
return 0;
}
}
return 0;
}