**Here is my code for optimal denomination problem from div 3 july long challenge.I don’t know why it is giving TLE for first subtask(if it is correct answer for second subtask)**

```
#include"bits/stdc++.h"
using namespace std;
#define ll long long int
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t;
cin>>t;
while(t--)
{
ll n;
cin>>n;
if(n==1)
{
cout<<"1"<<endl;
continue;
}
vector<ll> prefix(n);
vector<ll> suffix(n);
vector<ll> arr(n);
ll sum=0;
for(ll i=0;i<n;i++)
{
cin>>arr[i];
sum+=arr[i];
}
prefix[0]=arr[0];
suffix[n-1]=arr[n-1];
for(ll i=1;i<n;i++)
{
prefix[i]=__gcd(arr[i],prefix[i-1]);
suffix[n-i-1]=__gcd(arr[n-i-1],suffix[n-i]);
}
ll ans=sum/prefix[n-1];
for(ll i=0;i<n;i++)
{
ll temp=(sum-arr[i])/__gcd((i-1<0?0:(prefix[i-1])),(i+1>=n?0:suffix[i+1]));
ans=min(ans,temp);
}
cout<<ans+1<<endl;
}
return 0;
}```
```