-
Notifications
You must be signed in to change notification settings - Fork 0
/
39.cpp
38 lines (36 loc) · 773 Bytes
/
39.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
#include <cstdio>
#include <cmath>
// a^2 + b^2 = c^2
// a + b + c = p
// a <= b < c
// a + b > c
// p <= 1000
int main() {
constexpr int limit = 1000;
int ps[limit + 1];
for (auto &cnt : ps) cnt = 0;
for (int a = 1; a <= 500; ++a) {
for (int b = a; b <= 500; ++b) {
double c_ = std::sqrt(a * a + b * b);
int c = c_;
if (std::abs(c - c_) > 0.00001) continue;
int p = a + b + c;
if (p <= limit) ++ps[p];
else break;
// if (p <= limit) {
// printf("%d=%d+%d+%d ", p, a, b, (int) c);
// printf("%d %d\n", a * a + b * b, c * c);
// }
}
}
int bestp = 0;
int best_cnt = 0;
for (int p = 0; p <= limit; ++p) {
if (ps[p] > best_cnt) {
best_cnt = ps[p];
bestp = p;
}
}
std::cout << bestp << std::endl;
}