Discussion About Vivek's Homework

This is Discussion thread about Vivek’s Homework

#include
#include

using namespace std;
int main() {
int n;cin>>n;int arr[n],prd=1;
for(int i=0;i<n;i++){
cin>>arr[i];prd *= arr[i];
}
cout<< (int)(pow( prd, 1/(float)n)) +1 ;

return 0;

}

What is wrong in my code? Why are the test case giving wrong answer ?

1 Like


What is wrong in my code please check and tell.
Vivek homework

PLease check above code

Hello,
The above code assumes that we have to change the all the values to an element PRESENT in the Array but this condition is NOT given in the problem statement. So I think the correct answer should be next greater integer of nth root of the products of the elements of array.
i.e if there are 5 elements in array vis a vis 1 2 3 4 5 then ans is ceil((5!)^(1/5))

is this the answer of my question

Please check this code:

int n = 0;
Scanner scan=new Scanner(System.in);
if(scan.hasNextInt()) {
n=scan.nextInt();
}
long array[]=new long[n];
long mul=1;
for(int i=0;i<n;i++) {
array[i]=scan.nextLong();
mul*=array[i];
}
double x= Math.pow(mul,(float)1/n);
System.out.println((int)++x);

What is wrong with this code