Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define _test int _TEST; cin>>_TEST; while(_TEST--)
- #define ff first
- #define ss second
- #define pb push_back
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- cout.tie(NULL);
- _test
- {
- int n;
- cin>>n;
- vector<int> a(n);
- for(auto &e: a)
- cin>>e;
- int q;
- cin>>q;
- set<int> roots;
- map<int, ll int> cnt;
- for(auto e: a)
- cnt[e]++;
- int aj;
- while(q--)
- {
- ll int x, y;
- cin>>x>>y;
- if(x*x < 4*y)
- {
- cout<<0<<"\n";
- continue;
- }
- ll int val = x*x - 4*y;
- ll int sq = sqrtl(val);
- if(val != sq*sq)
- {
- cout<<0<<"\n";
- continue;
- }
- roots.clear();
- if((x+sq)%2 == 0) roots.insert((x + sq)/2);
- if((x-sq)%2 == 0) roots.insert((x - sq)/2);
- ll int ans = 0;
- for(auto ai: roots)
- {
- aj = x-ai;
- ans += (cnt[ai]*cnt[aj]);
- if(ai == aj) ans -= cnt[ai];
- }
- cout<<ans/2<<" ";
- }
- cout<<"\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment