can someone optimise this code

int main()

{

long n,k;

scanf("%ld\n",&n);

long a[n];

for(long i= 0;i<n;i++)

scanf("%ld\n",&a[i]);

for(long i=0;i<n;i++)

{

k=0;

for(long j=3;j<a[i];j++)

if(j%3==0 || j%5==0)

k=k+j;

if(k>0)

printf("%ld\n",k);

else

printf("%ld\n",k);

}

return 0;

}

Is it for https://www.hackerrank.com/contests/projecteuler/challenges/euler001 ?

The code has to be corrected first since it does not read input properly. You need to remove \n from the scanf calls.

Secondly, there are a lot of references on the net how to solve problem #1 of Project Euler. See for example https://www.mathblog.dk/project-euler-problem-1/