In ALATE problem ,my solution got AC for first subtask and TLE for second subtask,i modified it and now

#include #define MAX 1000000007 long long func(long long A[],int x,int N) { long long sum = 0; int i; //printf("n is %d and x is %d\n",N,x); for(i=x;i<=N;i+=x) { sum = ((sum + (A[i]*A[i])%MAX)%MAX); } return sum; } int main() { int n,i; scanf("%d",&n); long long a[1000001]; for(i=0;i<n;i++) { int y,z,j,b,c,d; long long e; scanf("%d %d",&y,&z); for(j=0;j<y;j++) { scanf("%lld",&a[j+1]); } long long sum[10]; //printf("here\n"); for(j=1;j<y && j<8;j++) { sum[j] = func(a,j,y); } for(j=0;j<z;j++) { scanf("%d %d",&b,&c); if(b == 1) { if(c <= 1) { printf("%lld\n",sum[c]); } else { printf("%lld\n",func(a,c,y)); } } else { scanf("%lld",&e); int k; sum[1] = (sum[1] - (a[c]*a[c])%MAX + (e*e)%MAX)%MAX; if( c % 2 == 0) { sum[2] = (sum[2] - (a[c]*a[c])%MAX + (e*e)%MAX)%MAX; } if(c%3 == 0) { sum[3] = (sum[3] - (a[c]*a[c])%MAX + (e*e)%MAX)%MAX; } if(c%4 == 0) { sum[4] = (sum[4] - (a[c]*a[c])%MAX + (e*e)%MAX)%MAX; } if(c%5 == 0) { sum[5] = (sum[5] - (a[c]*a[c])%MAX + (e*e)%MAX)%MAX; } if(c%6 == 0) { sum[6] = (sum[6] - (a[c]*a[c])%MAX + (e*e)%MAX)%MAX; } if(c%7 == 0) { sum[7] = (sum[7] - (a[c]*a[c])%MAX + (e*e)%MAX)%MAX; } a[c] = e; } } } return 0; }`enter code here` what is the problem in this,it gives wrong answer