#include <stdio.h>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
int c[25001013];
int main() {
int n;
scanf("%d" , &n);
int ret = 0;
for (int a = 1; a <= n; a++)
for (int b = a; a*a+b*b < n*n; b++)
c[a*a+b*b]++;
for (int p = 1; p <= n; p++)
for (int h = 1; h < p; h++)
ret += c[p*p-h*h];
printf("%d\n", ret);
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #include <stdio.h> #include <vector> #include <algorithm> #include <utility> using namespace std; int c[25001013]; int main() { int n; scanf("%d" , &n); int ret = 0; for (int a = 1; a <= n; a++) for (int b = a; a*a+b*b < n*n; b++) c[a*a+b*b]++; for (int p = 1; p <= n; p++) for (int h = 1; h < p; h++) ret += c[p*p-h*h]; printf("%d\n", ret); return 0; } |
English