Help me in solving POWPM problem

My issue

Can anyone explain me how can I approach the problem. I think bit manipulation will be used here to reduce time complexity.

My code

#include <iostream>
using namespace std;
#include<bits/stdc++.h>
int main() {
	// your code goes here
	long long int t;
	cin>>t;
	while(t--){
	    int n;
	    cin>>n;
	    vector<int> a;
	    for(int i=0;i<n;i++){
	        int a1;
	        cin>>a1;
	        a.push_back(a1);
	    }
	    
	    
	    int count=0;
	    for(int i=0;i<n;i++){
	        for(int j=0;j<n;j++){
	            if(a[i]>a[j]){
	                continue;
	            }
	            if(pow(a[i],j+1)<=a[j]){
	                count++;
	            }
	        }
	    }
	    
	    cout<<count<<endl;
	}
	
	return 0;
}

Problem Link: Powered Parameters Practice Coding Problem - CodeChef

@biswadeep_iiit
plzz refer my c++ code for better understanding of the logic

#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    long long int n;
	    cin>>n;
	    long long int a[n],ans=0;
	    for(int i=0;i<n;i++)
	    {
	        cin>>a[i];
	    }
	    for(int i=0;i<n;i++)
	    {
	        if(a[i]==1)
	        ans+=n;
	        else
	        {
	            long long int val=1;
	            for(int j=0;j<min(32LL,n);j++)
	            {
	                val*=a[i];
	                if(val>1e9)
	                break;
	                if(val<=a[j])
	                ans++;
	            }
	        }
	    }
	    cout<<ans<<endl;
	}
	return 0;
}