2 testcases are failing .Here’s the code:
Deepak and Primes
The 5,000,000th prime is 86,028,121.
so atleast this much space you require
as size of array is long and you need to save only 1 or 0
so rather than int use bool arr[100000001]={};
do some more optimzations like
iterate only odd nos as all prime are odd except 2
you can take help from this
// PrimeSeive.cpp
#include<iostream>
#include<vector>
using namespace std;
#define ll long long int
bool prime [100000005]={};
vector<int> Prime;
int main(){
prime[0]=prime[1]=true;
Prime.push_back(2);
for(ll i=3;i<100000001;i+=2){
if(!prime[i]){
Prime.push_back(i);
for(ll j=i*i;j<100000001;j+=i){prime[j]=true;}
}
}
int n;cin>>n;
cout<<Prime[n-1]<<endl;
return 0;
}
if i increase size of n or prime array then it gives error segmentation fault
Have you make bool array?
And do optimization?
Send me link or code
I will see
yes i did change the data type of array and now i am iterating to odd nos. only but still one test case is failing…i think its may be bcoz 1<=n<=5000000 n we are storing prime nos. till 1000000…how to find rest of the prime nos.
make arrays of size 10^8
and make global array
after that your code is giving correct ans
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.