Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- long countTriplets(vector<long> arr, long r) {
- unordered_map<long,long> rm;
- unordered_map<long,long> lm;
- int i;
- long sum=0;
- for(i=0;i<arr.size();i++)
- {
- rm[arr[i]]++;
- }
- for(i=0;i<arr.size();i++)
- {
- rm[arr[i]]--;
- if(arr[i]%r==0)
- {
- sum += (lm[arr[i]/r]) * (rm[arr[i]*r]);
- }
- lm[arr[i]]++;
- }
- return sum;
- }
Add Comment
Please, Sign In to add comment