AMR11E - Distinct Primes - SPOJ Solution C++

  Problem Link : AMR11E  


👉 Hint : edit please

 


✅ C++ Solution :

 
#include<bits/stdc++.h>
using namespace std;
int pr[100000];
set<int>s;
void findPrimes(int n)
{
	for(int i=2;i<=n/2;i++)
	{
		if(pr[i]==0)
		{
		 
			for(int j=2*i;j<=n;j+=i)
			{
			
				pr[j]++;
		
				if(pr[j]==3)
					s.insert(j);

			}
		}
	}

}

int main()
{
	int t;
	cin>>t;
	memset(pr,0,sizeof(pr));
	findPrimes(100000);
	while(t--)
	{
		int n,k=0;
		cin>>n;
		for(auto it=s.begin();it!=s.end();it++)
		{
			++k;
			if(k==n)
			{
				cout<<*it<<endl;
				break;
			}
		}
	}
}

 

Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook. 

😇Happy Learning!!