LOCAUG17 (which has ended) ALATE problem help

please help me and suggest me any error or additions to the code
i am getting the correct output that is mentioned in the example but the codechef is not accepting it

#include<stdio.h>

#define mod 1000000007

int n,ar[100001];

int query1(int x)
{

int sum = 0 ;

for(int i=x;i<=n;i+=x)

sum = sum + ((ar[i]*ar[i])%mod);

return sum%mod ;

}

int main()
{

int t;
scanf("%d",&t);
while(t--)
{
	int q,i,qt,x,y;
	scanf("%d %d",&n,&q);
	
	for(i=1;i<=n;i++)
	scanf("%d",&ar[i]);
	
	while(q--)
	{
		scanf("%d",&qt);
		
		if(qt==1)
		{
			scanf("%d",&x);
			printf("%d\n",query1(x));
			
		}
		if(qt==2)
		{
		scanf("%d %d",&x,&y);
		ar[x]=y;	
		}
	}
}

return 0;
}

Hey @sachin_123yad

You are applying brute force, and there is a better method to do this question. which I have answered here. please have a look here.

Why Your code is not working?

  • one of possible reason is use of int, since A[i] can be as large as possible 10^9 and other possible errors.

Hope this helps!

thanks @sandeep_007
yeah i got ur point and acknowledged my mistake…
i have also seen ur code and its good…
thank you …for seeing and answering to my query

your welcome buddy, if you think your query is answered please mark it as accepted so that this answer can be removed from un-answered question.