Can anyone tell me why i am getting tle in only last two test cases for subtask 2nd , for ques NMNMX

code:

//ll binomialCoeff(ll n, ll k)

{

ll res = 1;

if ( k > n - k )

k = n - k;

for (ll i = 0; i < k; ++i)

{

res *= (n - i);

res /= (i + 1);

res = res%mod;

}

return res;

}

ll power(ll x, ll y)

{

ll res = 1;

x = x % mod;

while (y > 0)

{

if (y & 1)

res = (res*x) % mod;
y = y>>1;
x = (x*x) % mod;

}

return res;

}

int main(){

go;

ll t;

cin>>t;

while(t–){

ll i,j,n,k;

cin>>n>>k;

ll a[n+1]={0};

ain(a,n);

sort(a,a+n);

ll b[n+1]={0},z=n,val=0;

lop(i,n){

val = (binomialCoeff(z,k) * k)/ z;

b[i]+=val;

z–;

if(val==1) break;

}

z = n;

for(i=n-1;i>=0;i–){

val = (binomialCoeff(z,k) * k)/ z;

b[i]+=val;

z–;

if(val==1) break;

}

val = binomialCoeff(n,k);

val = (val *k)/n;
lop(i,n) b[i] = val-b[i];
//for(i=0;i<n;i++) cout<<a[i]<<" : “<<b[i]<<” ";
ll ans=1;
loop(i,1,n-2){
ans*= power(a[i],b[i]);

ans = ans%mod;

}

cout<<ans<<endl;

}

return 0;

}

//