Not getting right output

this is the link of the hackerblock question named vivek homework-hachttps://hack.codingblocks.com/app/practice/1/70/problem

please find the flaw in my code
#include
#include<math.h>

using namespace std;
int main()
{
long long int n,pro=1,max=0,first,last,mid,ans,i;
cin>>n;

long long int a[n];

for(i=0;i<n;i++)
{
	cin>>a[i];
	pro=a[i]*pro;
}

first=0;
last=10000000001;

while(first<=last)
{
    mid=(first+last)/2;
    if(pow(mid,n)>pro)
    {
        ans=mid;
        last=mid-1;
    }

    else
    first=mid+1;
}

cout<<ans;

return 0;

}

hello @shivamgoel150
array value can be upto 10^10 and n can be upto 10^5
so in worst case ur multiplication can be (10^10) ^(10^5) which is clearly very big number and we dont have any datatype to store this .

now what we want to check
a[0]*a[1]*a[2]…*a[n-2]*a[n-1]<=x^n

take log both side
log(a[0]*a[1]*a[2]…a[n-2]a[n-1])<= nlog(x)
using log(a
b)=log(a)+log(b)

log(a[0])+log(a[1])+log(a[2])…log(a[n-1]<=n*log(x)

so use above trick to search optimal x. without doing multiplication .