#include
using namespace std;
int prime(int n) //n=15
{
int ctr=0;
for(int i=1;i<=n;i++)
{
if(n%i==0)
ctr++;
}
if(ctr==2)
return 1;
else
return 0;
}
int main() {
int t;
cin>>t;
while(t--)
{
long long int n,i,k,j=0;
cin>>n; //n=15
long long int pr[n];
for(i=2;i<=n;i++) //i = 2 to 15
{
if(prime(i)==1)
pr[j++]=i;
} //pr[6] = {2,3,5,7,11,13}
int sum[n],p=0;
for(k=0;k<j;k++)
{
for(i=2;i<=n;i++)
{
if(i%pr[k]==0)
sum[p++]=i; //sum[18] = {2,4,6,8,10,12,14,3,6,9,12,15,5,10,15,7,11,13}
}
}
int ctr[101]={0};
int len = sizeof(sum)/sizeof(sum[0]);
for(i=0;i<len;i++)
{
ctr[sum[i]]++;
if(ctr[sum[i]]>1)
len=len-1;
}
cout<<len<<"\n";
}
return 0;
}
The code is running fine for few test cases, and giving wrong output for other test cases. (e.g. it’s running for input=10 but giving wrong output for input=15).