#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include <bits/stdc++.h>
#define FOR(i,p,k) for(int i=(p);i<=(k);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define RFOR(i,p,n) for(int i=(p);i>=(n);--i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define ssize(x) int((x).size())
#define fi first
#define se second
#define V vector
#define pb push_back
#define eb emplace_back
#define C const
#define pn printf("\n")
using namespace std;
typedef long long ll;
typedef V<int> vi;
typedef V<ll> vll;
typedef const int ci;
typedef const ll cll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
void chmin(auto &a, auto b){a=min(a,b);}
void chmax(auto &a, auto b){a=max(a,b);}
ci inf = 2.1e9;
cll infll = 4.5e18;
int I(){
int z;
scanf("%d", &z);
//cin >> z;
return z;
}
void answer(){
int n = I();
vi tab(n*n + n*n + 1, 0);
FOR(a, 1, n) FOR(b, 1, a) ++tab[a*a+b*b];
ll wyn = 0;
FOR(k, 1, n) FOR(h, 1, k) wyn += tab[k*k - h*h];
printf("%lld\n", wyn);
}
int main(){
//ios_base::sync_with_stdio(0);
//cin.tie(0);
int tt = 1;
//tt = I();
while(tt--) answer();
}
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 44 45 46 47 48 49 50 51 52 53 | #ifndef LOCAL #pragma GCC optimize("O3") #endif #include <bits/stdc++.h> #define FOR(i,p,k) for(int i=(p);i<=(k);++i) #define REP(i,n) FOR(i,0,(n)-1) #define RFOR(i,p,n) for(int i=(p);i>=(n);--i) #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define ssize(x) int((x).size()) #define fi first #define se second #define V vector #define pb push_back #define eb emplace_back #define C const #define pn printf("\n") using namespace std; typedef long long ll; typedef V<int> vi; typedef V<ll> vll; typedef const int ci; typedef const ll cll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; void chmin(auto &a, auto b){a=min(a,b);} void chmax(auto &a, auto b){a=max(a,b);} ci inf = 2.1e9; cll infll = 4.5e18; int I(){ int z; scanf("%d", &z); //cin >> z; return z; } void answer(){ int n = I(); vi tab(n*n + n*n + 1, 0); FOR(a, 1, n) FOR(b, 1, a) ++tab[a*a+b*b]; ll wyn = 0; FOR(k, 1, n) FOR(h, 1, k) wyn += tab[k*k - h*h]; printf("%lld\n", wyn); } int main(){ //ios_base::sync_with_stdio(0); //cin.tie(0); int tt = 1; //tt = I(); while(tt--) answer(); } |
English