DOUBT IN CODE (giving wrong output for few test cases)

#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).

hi @pratyushnitdgp19_2c287088d77b5893
kindly save your code on coding blocks ide and send link…

Sir, I couldn’t find any option to save, how do I save the code on Coding Blocks IDE?

Hi @pratyushnitdgp19_2c287088d77b5893
Go to https://ide.codingblocks.com/
Write ur code, then there is file drop-down… click on it and click save… then send the url…

https://ide.codingblocks.com/s/647801

hi @pratyushnitdgp19_2c287088d77b5893
try this -->

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.