Problem->[ALATE]: https://www.codechef.com/LOCAUG17/problems/ALATE

Please give suggestions to improve my code so that it passes Sub task 2 without TLE(Please help me)

#include bits/stdc++.h #define ll long long #define MOD 1000000007 #define N 1000005 using namespace std; ll a[N],n; ll func(ll x) { ll k,sum=0; for(ll i=x;i<=n;i+=x) { k=(a[i]*a[i])%MOD; sum=(sum+(a[i]*a[i]))%MOD; sum%=MOD; } return sum; } int main() { ll t,q,i,j,qno,x,y; scanf("%lld",&t); while(t--) { scanf("%lld%lld",&n,&q); for(i=1;i<=n;i++) scanf("%lld",&a[i]); for(j=1;j<=q;j++) { scanf("%lld",&qno); if(qno==1) { scanf("%lld",&x); printf("%lld\n",func(x)); } else { scanf("%lld%lld",&x,&y); a[x]=y; } } } return 0; } ```