#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define F first #define S second #define pii pair<int,int> #define vi vector<int> #define vpii vector<pii> #define loop(i,n) sloop(0,i,n) #define sloop(s, i, n) for(ll i=(s);i<(n);i++) #define rloop(i,n) rsloop(0,i,n) #define rsloop(s,i,n) for(ll i=(n);i-->(s);) #define all(v) (v).begin(),(v).end() #ifdef DEBUG #define DBG cout << __LINE__ << endl; #else #define DBG #endif //int xses[8] = {-1,1,0,0,-1,1,1,-1}; //int yses[8] = {0,0,-1,1,-1,1,-1,1}; #define int ll int n; vi kwadraty; int target; int twoSum(int t) { unordered_set<int> s; loop(i,kwadraty.size()){if(t-kwadraty[i]>0)s.insert(t-kwadraty[i]);} int res=0; loop(i,kwadraty.size())if(s.count(kwadraty[i])>0){res++; //cout << kwadraty[i]<< ' ' << t-kwadraty[i] << ' ' << target*target-t<< endl; } return (res+1)/2; } void solve() { cin >> n; for(int i=1;i<n;i++)kwadraty.pb(i*i); //loop(i,kwadraty.size())cout<<kwadraty[i]<<' ';cout<<endl; int res=0; for(target=1;target<n+1;target++) { loop(i,kwadraty.size()) { if(target*target-kwadraty[i]<1)continue; res+= twoSum(target*target-kwadraty[i]); } } cout << res; } signed main() { cin.tie(0); ios_base::sync_with_stdio(0); int t=1; //cin >> t; while(t--) 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 | #include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define F first #define S second #define pii pair<int,int> #define vi vector<int> #define vpii vector<pii> #define loop(i,n) sloop(0,i,n) #define sloop(s, i, n) for(ll i=(s);i<(n);i++) #define rloop(i,n) rsloop(0,i,n) #define rsloop(s,i,n) for(ll i=(n);i-->(s);) #define all(v) (v).begin(),(v).end() #ifdef DEBUG #define DBG cout << __LINE__ << endl; #else #define DBG #endif //int xses[8] = {-1,1,0,0,-1,1,1,-1}; //int yses[8] = {0,0,-1,1,-1,1,-1,1}; #define int ll int n; vi kwadraty; int target; int twoSum(int t) { unordered_set<int> s; loop(i,kwadraty.size()){if(t-kwadraty[i]>0)s.insert(t-kwadraty[i]);} int res=0; loop(i,kwadraty.size())if(s.count(kwadraty[i])>0){res++; //cout << kwadraty[i]<< ' ' << t-kwadraty[i] << ' ' << target*target-t<< endl; } return (res+1)/2; } void solve() { cin >> n; for(int i=1;i<n;i++)kwadraty.pb(i*i); //loop(i,kwadraty.size())cout<<kwadraty[i]<<' ';cout<<endl; int res=0; for(target=1;target<n+1;target++) { loop(i,kwadraty.size()) { if(target*target-kwadraty[i]<1)continue; res+= twoSum(target*target-kwadraty[i]); } } cout << res; } signed main() { cin.tie(0); ios_base::sync_with_stdio(0); int t=1; //cin >> t; while(t--) solve(); return 0; } |