easy cpp solution to understand
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int countPairs(vector<int>& nums, int target) {\n        ios_base ::sync_with_stdio(false), cin.tie(0), cout.tie(0);\n        int n = nums.size();\n        int count = 0;\n        sort(nums.begin(), nums.end());\n\n        for(int i = 0;i < (n - 1);i++){\n            int low = (i + 1);\n            int high = n - 1;\n            int ans = i;\n            int rem = target - nums[i];\n            while(low <= high){\n                int mid = (low + high) / 2;\n                if(nums[mid] < rem){\n                    low = mid + 1;\n                    ans = max(ans, mid);\n                }\n                else high = mid - 1;\n            }\n            count += (ans - i);\n        }\n        return count;\n    }\n};\n```
['C++']