Recently I came across this question and I'm able to write a code for this which works fine in all online compilers but showing segmentation fault in the problem page!! Can somebody help me to eliminate this error? The problem page is also linked which has the question and compiler where I'm getting a segmentation fault.
#include <stdio.h>
int main()
{
int num=0;
scanf("%d",&num);
long long int arr[num], i, j, k, m;
for(i=0; i<num; i++)
scanf("%lld",&arr[i]);
for(k=0; k<num; k++)
{
long long int val = arr[k];
long long int tmp[val], count=0;
for(m=1; m<=arr[k]; m++)
{
tmp[m] = 0;
}
for(i=1; i<=arr[k]; i++)
{
for(j=i; j<=arr[k]; j+=i)
{
if(tmp[j] == 0) { tmp[j] = 1; count++;}
else if(tmp[j] == 1) { tmp[j] = 0; count--;}
}
}
printf("%lld\n",count);
}
return 0;
}