Posts

Showing posts from October, 2017

Prime Number generator Using Sieve Algorithms

Prime Number Calculate Using Sieve Algorithms ********Problem 1********** You are given N, find the Nth prime number... N:B: 1 is not a prime number Input Format Only a number N Constraints 1 <= N <= 107 Output Format Y where Y is the prime number which is at Nth position. Print "invalid position" when Nth position prime is greater than 107. Sample Input 0 1 Sample Output 0 2 Explanation 0 first prime number is 2 Sample Input 1 5 Sample Output 1 11 Explanation 1 5th prime number is 11 ********Solve******** #include<bits/stdc++.h> using namespace std; #define ll long long vector<int>p; bitset<10000005>bs; bool ar[1000005]; bool isprime(long long x) {     if(x<=10000005)     {         return bs[x];     }     for(long long i=0; i<p.size(); i++)     {         if(x%p[i]==0)         {             return false;         }     }     return true; } void seive(long long n) {     long long i,j;     b