Help me in solving FIZZBUZZ2310 problem for TIME LIMIT EXCEED

My issue

Can anyone explain how the coefficient of a[i](an ith element in array A) can be solved for? Please provide math for it.
Thanks

My code

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vii vector<vector<int>>
#define mod 998244353

int main() {
	int t;cin>>t;
	while(t--){
       ll n;
       cin>>n;
       vector<ll> v(n+1,0);
       for(ll i=1;i<=n;i++){
           cin>>v[i];
       }
       ll res=0;
       for(ll s=1;s<=n;s++){
           for(ll e=s;e<=n;e++){
               ll len = e-s+1;
               for(ll pos = s;pos<=e;pos++){
                   res += v[pos]*(len-(2*(pos-s+1))+1);
                   res = res%mod;
               }  
           }
       }
       if(res<0) res+=mod;
       cout<<res%mod<<'\n';
       
	}
	return 0;
}

Problem Link: FIZZBUZZ2310 Problem - CodeChef

you can find the math for this problem in this: editorial

1 Like

Thanks bro

1 Like