AcWing 1221. 四平方和
原题链接
简单
作者:
回归线
,
2021-04-28 21:10:02
,
所有人可见
,
阅读 213
#include <iostream>
#include <cstring>
using namespace std;
const int N = 5000010;
int mc[N];
int md[N];
int main() {
int n;
cin >> n;
memset(mc, -1, sizeof mc);
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 (mc[s] == -1) {
mc[s] = c;
md[s] = 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 (mc[s] != -1) {
cout << a << ' ' << b << ' ' << mc[s] << ' ' << md[s] << endl;
return 0;
}
}
}
return 0;
}