Using Sieve of Eratosthenes
What is Sieve of Eratosthenes?
For those who are unaware with Sieve of Eratosthenes , here is a solution I've posted where I've discussed it from the complete b
# What is Sieve of Eratosthenes?\n- For those who are unaware with Sieve of Eratosthenes , here is a solution I\'ve posted where I\'ve discussed it from the complete basics as well as clarified all the FAQs --> [All About Sieve of Eratosthenes](https://leetcode.com/problems/closest-prime-numbers-in-range/solutions/6092610/all-about-sieve-of-eratosthenes/)\n\n# Approach\n- We basically just firstly generate the sieve which takes all the prime numbers upto the input n.\n- Secondary if we need to find `i + j = n` , its the same as \n`j = n - i`.\nTherefore we use `difference = n - i` and check that if the `difference` is a prime and `i` is a prime , if it is then we simply add it to our pair vector.\n- Lastly we return our pair vector which stores all the answers.\n\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    vector<vector<int>> findPrimePairs(int n) {\n        vector<vector<int>> nums;\n        vector<bool> sieve = generateSieve(n); \n        for (int i = 2; i <= n / 2; i++) {\n            int difference = n - i;\n            if (sieve[i] && sieve[difference]) { \n                nums.push_back({i, difference});\n            }\n        }\n        return nums;\n    }\n\n    // Using Sieve of Eratosthenes\n    vector<bool> generateSieve(int n) {\n        vector<bool> isPrime(n + 1, true);\n        isPrime[0] = isPrime[1] = false;\n        for (int i = 2; i * i <= n; ++i) {\n            if (isPrime[i]) {\n                for (int j = i * i; j <= n; j += i) {\n                    isPrime[j] = false;\n                }\n            }\n        }\n        return isPrime;\n    }\n};\n\n```
['C++']