#include<iostream>
#include<algorithm>
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
using namespace std;
const int MAX_N = 5000;
int T[1+MAX_N*MAX_N];
int U[1+MAX_N*MAX_N];
int n, n1, n2, m2, a2, b2, h2, res;
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
n1 = n-1;
n2 = n*n;
REP(i, n2) T[i] = U[i] = 0;
FOR(a,1,n1) {
a2=a*a;
FOR(b,a,n1) {
b2 = a2+b*b;
if (b2 >= n2) break;
T[b2]++;
}
}
FOR(h,1,n1) {
h2 = h*h;
FOR(m,h,n) U[m*m-h2] += 1;
}
res = 0;
FOR(i, 1, n2-1) res += T[i]*U[i];
cout << res;
return 0;
}
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 39 40 41 42 43 | #include<iostream> #include<algorithm> #define REP(i,n) for(int i=0;i<(n);++i) #define FOR(i,a,b) for(int i=(a);i<=(b);++i) using namespace std; const int MAX_N = 5000; int T[1+MAX_N*MAX_N]; int U[1+MAX_N*MAX_N]; int n, n1, n2, m2, a2, b2, h2, res; int main(void) { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; n1 = n-1; n2 = n*n; REP(i, n2) T[i] = U[i] = 0; FOR(a,1,n1) { a2=a*a; FOR(b,a,n1) { b2 = a2+b*b; if (b2 >= n2) break; T[b2]++; } } FOR(h,1,n1) { h2 = h*h; FOR(m,h,n) U[m*m-h2] += 1; } res = 0; FOR(i, 1, n2-1) res += T[i]*U[i]; cout << res; return 0; } |
English