Question Link : Powered Parameters Practice Coding Problem - CodeChef
My Code :
include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
while(t–){
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++){
cin>>arr[i];
}
long long ans = 0;
int x = min(30,n);
for(int i=0;i<n;i++){
if(arr[i] == 1){
ans+=n;
continue;
}
for(int j = 1;j<x;j++){
if(pow(arr[i],j) <= arr[j-1])
ans++;
}
}
cout<<ans<<endl;
}
}
Code which passing all TC’s
include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
while(t–){
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++){
cin>>arr[i];
}
long long ans = 0;
int x = min(30,n);
for(int i=0;i<n;i++){
if(arr[i] == 1){
ans+=n;
continue;
}
for(int j = 0;j<x;j++){
if(pow(arr[i],j+1) <= arr[j])
ans++;
}
}
cout<<ans<<endl;
}
}
Changing only pow function and loop resulting in Test cases Passing. I cannot see what Testcase is Failing. So I cannot deduce what is wring in First code. Please help.