Help me in solving POWPM problem

My issue

code failed on the last test case.
APPROACH-
find the largest power of Ai such that Ai^maxPow<=largest element of the array.
check for each value of j, 0<=j<maxPow Ai^j<=Aj. If true add to answer.
what is wrong with this approach and implementation?

My code

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



int  sol(long long num, long long b,vector<long long> &a){
     int maxPow=log(num)/log(b);
     int cnt=0;
    //  cout<<maxPow<<" ";
     while(maxPow){
         if(pow(b,maxPow)<=a[maxPow-1])
         cnt++;
        //  if(maxPow<=log(a[maxPow-1]/log(b)))
        //  cnt++;
         
         maxPow--;
         
         
     }
     return cnt;
}

int main() {
    int t;cin>>t;
    while(t--){
        int n;
        cin>>n;
        vector<long long>a(n);
        for(int i=0;i<n;i++)
        cin>>a[i];
        
        long long maxi=*max_element(a.begin(),a.end());
        long long ans=0;
        for(int i=0;i<n;i++){
            if(a[i]==1)
            ans+=n;
            
            else
            ans+=sol(maxi,a[i],a);
        }
        cout<<ans<<"\n";
        
    }
	
	
	  return 0;
}

Problem Link: Powered Parameters Practice Coding Problem - CodeChef