🔥✌️✅ Sieve of Eratosthenes | Prime Pair With Target Sum | C++ Easy
Approach\nFirst we have generated all the prime number from the Algorithm\n"sieve of eratosthenes" using a boolean array of prime numbers...and then used for lo
# Approach\nFirst we have generated all the prime number from the Algorithm\n"sieve of eratosthenes" using a boolean array of prime numbers...and then used for loop to iterate over the prime numbers and marked the prime number as false which are used...\n\n# Time Complexity\n- Time complexity: TC for generating Sieve of Eratosthenes-->O(nlog(logn))\n- TC->O(n) for iterating over the sieve for integer n\n\n# Code\n```\nclass Solution {\npublic:\n    \nvoid sieve(int n,vector<bool>&isPrime){\n    \n    isPrime[0]=isPrime[1]=false;\n    \n    for (int p = 2; p * p <= n; p++) {\n      \n        if (isPrime[p] == true) {\n            for (int i = p * p; i <= n; i += p)\n                isPrime[i] = false;\n        }\n    }\n}\n\n    vector<vector<int>> findPrimePairs(int n) {\n        \n        vector<bool> isPrime(n+1, true);\n          vector<vector<int>>ans;\n    \n        sieve(n,isPrime);\n        \n        for(int i=2;i<=n;i++){\n            if(isPrime[i] && isPrime[n-i]){\n                isPrime[i]=false;\n                isPrime[n-i]=false;\n                ans.push_back({i,n-i});\n            }\n        }\n      \n        return ans;\n    }\n};\n```
['C++']