UPPER_BOUND | C++
Code\n\nclass Solution {\npublic:\nint power(long long x, unsigned int y, int p)\n{\n    int res = 1;     \n    x = x % p; \n    if (x == 0) return 0; \n    whi
# Code\n```\nclass Solution {\npublic:\nint power(long long x, unsigned int y, int p)\n{\n    int res = 1;     \n    x = x % p; \n    if (x == 0) return 0; \n    while (y > 0)\n    {\n        if (y & 1)\n            res = (res*x) % p;\n        y = y>>1; \n        x = (x*x) % p;\n    }\n    return res;\n}\nint MOD = 1e9 + 7;\n    int numSubseq(vector<int>& nums, int target) {\n        sort(nums.begin(),nums.end());\n        int ans = 0;\n        for(int i = 0; i < nums.size(); ++i){\n\n            int val = target - nums[i];\n            int idx = upper_bound(nums.begin(),nums.end(),val) - nums.begin();\n            idx--;\n            if(idx >= i){\n                ans = (ans + power(2,idx-i,MOD))%MOD;\n            }\n        }\n        return ans%MOD;\n    }\n};\n```
['C++']