Approach
# 模擬a, b, c計算等式
Simulate the calculation of the equation using a, b, and c.
Time Complexity
O(n * n * n)
Space Complexity
O(1)
Code
class Solution {
public:
int countTriples(int n) {
int cnt = 0;
for (int a = 1 ; a < n ; a++) {
for (int b = 1 ; b < n ; b++) {
for (int c = 1 ; c <= n ; c++) {
if (a * a + b * b == c * c) {
cnt++;
}
}
}
}
return cnt;
}
};