Fredo Game

QUESTION

Fredo is assigned a task today. He is given an array A containing N integers. His task is to update all elements of array to some minimum value x that is, A[i]=x; i<=1<=N such that product of all elements of this new array is strictly greater than the product of all elements of the initial array. \n\nNote that x should be as minimum as possible such that it meets the given condition. Help him find the value of x.\n\nInput Format:\nThe first line consists of an integer N denoting the number of elements in the array.\nThe next line consists of N space separated integers, denoting the array elements.\n\nOutput Format:\nThe only line of output consists of value of x\n\nInput Constraints:\n \n1<=N<=10 to the power 5\n1<=A[i]<=10 to the power 10\nA[i] denoting an array element.\n\nInitial array product = 4*2*1*10*6=480.\nIf all elements becomes 4 then product=4*4*4*4*4=1024.Had all elements become 3\n3, product would be =243 which is less than 480\n\nHence, value of \nx is 4.

“TESTCASE_1”: “5\n4 2 1 10 6\n###—###SEPERATOR—###—\n4”, “TESTCASE_2”: “5\n27 253 316 3830 2384\n###—###SEPERATOR—###—\n456”, “TESTCASE_3”: “0\n###—###SEPERATOR—###—\n0”, “TESTCASE_4”: “0\n###—###SEPERATOR—###—\n0”, “TESTCASE_5”: “0\n###—###SEPERATOR—###—\n0

ANSWER

#include <stdio.h>
#include <math.h>
int main()
{
    int n;
    scanf("%d",&n);
    unsigned long long int a,q=1;
    long double p=1.0;
  int i;
    for(i=1;i<=n;i++){
        scanf("%lld",&a);
        p*=pow(a,1.0/n);
    }
     int r=floor(p);
    r++;
    printf("%d\n",r);
    return 0;
}
Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
Best Wordpress Adblock Detecting Plugin | CHP Adblock