#include <memory.h>
#include <stdio.h>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <ranges>
#include <locale>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <string_view>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
#define fst first
#define snd second
#define X first
#define Y second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define sz(v) ((int)(v).size())
#define sqr(x) ((x) * (x))
typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
// #define next ajksdslk
// #define prev aklsfjk
mt19937_64 mt_rand(chrono::system_clock::now().time_since_epoch().count());
template <typename T1, typename T2>
inline bool upmax(T1& a, T2 b) {
return (a < b ? (a = b, true) : false);
}
template <typename T1, typename T2>
inline bool upmin(T1& a, T2 b) {
return (b < a ? (a = b, true) : false);
}
const int maxn = (int)(1e6 + 10);
const int maxlog = 21;
const int base = (int)1e9 + 7;
const ld eps = (ld)1e-9;
const ld PI = acos(-1.);
// const int pp = 41;
const int inf = 1e9;
const ll llinf = 2e18;
const int MOD = 998244353;
const int N = 5000;
int f[2 * (N + 1) * (N + 1) + 10];
void precalc() {
for (int a = 1; a <= N; a ++) {
for (int b = a; b <= N; b ++) {
f[sqr(a) + sqr(b)] ++;
}
}
}
int solve2(int nmax) {
int ans = 0;
for (int n = 1; n <= nmax; n++) {
for (int h = 1; h <= n; h ++) {
ans += f[sqr(n) - sqr(h)];
}
}
return ans;
}
void solve() {
int n; cin >> n;
cout << solve2(n) << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
precalc();
int t = 1;
// cin >> t;
for (int i = 1; i <= t; i++) {
// cout << "Case #" << i << ": ";
solve();
}
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | #include <memory.h> #include <stdio.h> #include <algorithm> #include <array> #include <bitset> #include <cassert> #include <cctype> #include <chrono> #include <cmath> #include <cstdio> #include <cstdlib> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <ios> #include <iostream> #include <iterator> #include <limits> #include <list> #include <ranges> #include <locale> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <string> #include <string_view> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> // #pragma GCC target("sse,sse2,sse3,ssse3,sse4") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") using namespace std; #define fst first #define snd second #define X first #define Y second #define mp make_pair #define mt make_tuple #define pb push_back #define eb emplace_back #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define sz(v) ((int)(v).size()) #define sqr(x) ((x) * (x)) typedef long long ll; typedef double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; // #define next ajksdslk // #define prev aklsfjk mt19937_64 mt_rand(chrono::system_clock::now().time_since_epoch().count()); template <typename T1, typename T2> inline bool upmax(T1& a, T2 b) { return (a < b ? (a = b, true) : false); } template <typename T1, typename T2> inline bool upmin(T1& a, T2 b) { return (b < a ? (a = b, true) : false); } const int maxn = (int)(1e6 + 10); const int maxlog = 21; const int base = (int)1e9 + 7; const ld eps = (ld)1e-9; const ld PI = acos(-1.); // const int pp = 41; const int inf = 1e9; const ll llinf = 2e18; const int MOD = 998244353; const int N = 5000; int f[2 * (N + 1) * (N + 1) + 10]; void precalc() { for (int a = 1; a <= N; a ++) { for (int b = a; b <= N; b ++) { f[sqr(a) + sqr(b)] ++; } } } int solve2(int nmax) { int ans = 0; for (int n = 1; n <= nmax; n++) { for (int h = 1; h <= n; h ++) { ans += f[sqr(n) - sqr(h)]; } } return ans; } void solve() { int n; cin >> n; cout << solve2(n) << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); #ifdef LOCAL freopen("input.txt", "r", stdin); #endif precalc(); int t = 1; // cin >> t; for (int i = 1; i <= t; i++) { // cout << "Case #" << i << ": "; solve(); } return 0; } |
English