#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define ll long long
#define ull unsigned ll
#define pb push_back
#define pii pair<int,int>
#define pl pair<ll,ll>
#define F first
#define S second
#define pq priority_queue
#define all(x) x.begin(), x.end()
#define deb(x) cout << #x << " = " << x << '\n';
#define deb2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << '\n';
constexpr int M = 1e9+7;
constexpr int N = 1e6+7;
constexpr bool debug = 0;
unordered_map<int,int> ways;
ll dop[5007];
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int m; cin >> m;
for(ll a = 1; a <= m; a++){
for(ll b = a; a*a + b*b <= m*m; b++){
ways[a*a+b*b]++;
}
}
for(ll n = 1; n <= m; n++){
dop[n] = dop[n-1];
for(ll h = 1; h <= n; h++){
dop[n] += ways[n*n-h*h];
}
}
cout << dop[m];
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 | #include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> using namespace std; //using namespace __gnu_pbds; #define ll long long #define ull unsigned ll #define pb push_back #define pii pair<int,int> #define pl pair<ll,ll> #define F first #define S second #define pq priority_queue #define all(x) x.begin(), x.end() #define deb(x) cout << #x << " = " << x << '\n'; #define deb2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << '\n'; constexpr int M = 1e9+7; constexpr int N = 1e6+7; constexpr bool debug = 0; unordered_map<int,int> ways; ll dop[5007]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int m; cin >> m; for(ll a = 1; a <= m; a++){ for(ll b = a; a*a + b*b <= m*m; b++){ ways[a*a+b*b]++; } } for(ll n = 1; n <= m; n++){ dop[n] = dop[n-1]; for(ll h = 1; h <= n; h++){ dop[n] += ways[n*n-h*h]; } } cout << dop[m]; return 0; } |
English