Time Limit exceed in Beautiful arrays

Please Help I can’t figure out why time limit is excedding?

#include
#include
using namespace std;

int main(){

int T,n;
string ans;
cin>>T;
for(int i=1;i<=T;i++){
    cin>>n;
    int ar[n];

    for(int j=0;j<n;j++){
        cin>>ar[j];
    }

    int temp=0;

    for(int j=0;j<n;j++){
        
        for(int k=0;k<n;k++){
            
            int temp1=0;
            if(j==k);
            else{
            for(int l=0;l<n;l++){

                if((ar[j]*ar[k])==ar[l])temp1++;

            }
            }
        if(temp1>0)temp++;

        }
    }
    if(temp==((n*n)-n)){
        ans = ans+"yes\n";
    }
    else ans=ans+"no\n";
}
cout<<ans<<endl;
return 0;

}

What is going on. No one is posting the problem link.
Pls provide problem link with your queries(highly recommended)

2 Likes

Whenever you ask a doubt about a problem, always provide the problem link.

I think you are discussing about the problem given in the following link.

https://www.codechef.com/problems/ICPC16B

According to the given constraints, N <= 10^5 and your code has 3 nested loops from 0 to N, so the complexity of your code is N * N * N (10^15 in the worst case). This is too much for a time limit of 2 seconds.

3 Likes