https://www.codechef.com/LOCAUG17/problems/ALATE....why this code is showing wrong answer?plz suggest something?

#include
#include <stdio.h>
using namespace std;
int main()
{int t;
scanf("%d",&t);

for(int i=0;i<t;i++)
{
int n;
scanf("%d",&n);

 int qu1;

scanf("%d",&qu1);
long int m=1000000007;
long int a[100002];
for( int q=1;q<=n;q++)
{ long int y;
scanf("%ld",&y);
a[q]=((y%m)*(y%m))%m;
}

long int v[100002];

for( int a1=1;a1<=n;a1++)
{ long int sum=0;
for( int a2=a1;a2<=n;a2+=a1)
{
sum+=a[a2];

}
v[a1]=sum%m;

}

for( int h=1;h<=qu1;h++)
{ int qw;
scanf("%d",&qw);
if(qw==1)
{
int x;
scanf("%d",&x);

  cout<<v[x]<<endl;

}

else if(qw==2)
{
int x;
scanf("%d",&x);
long int y;
scanf("%ld",&y);
long int t=(y*y)%m;
for( int a1=1;a1<=x;a1++)
{
if(x%a1==0)
{v[a1]=v[a1]-a[x];
v[a1]=v[a1]+t;
v[a1]=v[a1]%m;
}
}
a[x]=t;
}
}
}

return 0;

}

hey @harshvar786,

One of the possible reasons is that you are using long int, since we have to take a square of values and they can go up to 10^18 as 10^9*10^9 and it won’t fit in long int.

Hope this helps!

(for more explanation please look here.)