#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define EPSILON 1e-8

int* a;
int n;

double evaluate(double);

int main(int argc, char** argv)
{
 /* Variables. */
 int i;
 double l = 0.0;
 double r = 1.0;
 double where = -1.0;
 double old = -1.0;

 /* Check arguments. */
 if (argc < 2)
 {
  printf("BR-SYNTAX: br <n1> <n2> ...\n");
  return 1;
 }

 /* Extract arguments. */
 n = argc-1;
 a = (int*)malloc(sizeof(int)*n);
 for (i=1; i<argc; ++i)
 {
  a[i-1] = atoi(argv[i]);
 }

 /* Start bisection */
 do
 {
  /* Store last result. */
  old = where;

  /* Determine where to evaluate the polynomial. */
  where = (l+r)/2;
  if (evaluate(where) > 0.0) l = where; else r = where;
 }
 while (fabs(old-where) > EPSILON);

 /* Print the result. */
 printf("%f\n", 1.0/where);
 return 0;
}

double evaluate(double x)
{
 /* Variables. */
 int i;

 /* Evaulate the reflected characteristic polynomial. */
 double value = 1.0;
 for (i=0; i<n; ++i) value -= pow(x,a[i]); 
 return value;
}
