#include <bits/stdc++.h> using namespace std; typedef long long ll; #define vc vector #define st first #define nd second #define pll pair<ll, ll> #define sz(a) (ll)a.size() #define all(a) a.begin(), a.end() #define pu push #define pub push_back #define pob pop_back #define em emplace #define emb emplace_back void program() { ll n; cin >> n; vc<ll> ab(n * n + 1, 0); for (ll a = 1; a <= n; a++) for (ll b = a; b <= n; b++) { ll k = a * a + b * b; if (k <= n * n) ab[k]++; } ll ans = 0; for (ll d = 1; d <= n; d++) for (ll h = 1; h <= d; h++) ans += ab[d * d - h * h]; cout << ans << "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); program(); 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 | #include <bits/stdc++.h> using namespace std; typedef long long ll; #define vc vector #define st first #define nd second #define pll pair<ll, ll> #define sz(a) (ll)a.size() #define all(a) a.begin(), a.end() #define pu push #define pub push_back #define pob pop_back #define em emplace #define emb emplace_back void program() { ll n; cin >> n; vc<ll> ab(n * n + 1, 0); for (ll a = 1; a <= n; a++) for (ll b = a; b <= n; b++) { ll k = a * a + b * b; if (k <= n * n) ab[k]++; } ll ans = 0; for (ll d = 1; d <= n; d++) for (ll h = 1; h <= d; h++) ans += ab[d * d - h * h]; cout << ans << "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); program(); return 0; } |