#include <stdio.h>
#include "gmp.h"
#include "math.h"

#define P (65536)

int arccot( mpf_t ROP, mpf_t xp, mpf_t item, long long x, long long n ){
  long long i;

  mpf_set_ui( ROP, 0 );  
  mpf_set_ui( xp, 1 );
  
  mpf_div_ui( xp, xp, x );
  mpf_add( ROP, ROP, xp );
  
  for(i=2; i<n; i++){
    mpf_div_ui( xp, xp, x );
    mpf_div_ui( xp, xp, x);
    mpf_div_ui( item, xp, (2*i-1) );
    if(i%2==0)mpf_neg( item, item );
    mpf_add( ROP, ROP, item );
  }
  return 1;
}

int main(){
  mpf_t result1;
  mpf_t result2;
  mpf_t result3;
  long x1 = 2;
  long x2 = 5;
  long x3 = 8;
  mpf_t xp, item, result;

  mpf_set_default_prec(ceil(P*log2(10)) + 64 );

  mpf_init( result1 ); 
  mpf_init( result2 ); 
  mpf_init( result3 ); 
  mpf_inits( xp, item, result, NULL );
  mpf_set_ui( result, 0 );

  arccot( result1, xp, item, x1, P );
  arccot( result2, xp, item, x2, P );
  arccot( result3, xp, item, x3, P );

  mpf_add( result, result, result1 );
  mpf_add( result, result, result2 );
  mpf_add( result, result, result3 );
  mpf_mul_ui( result, result, 4 );
  mpf_out_str( NULL, 10, 0, result );

  mpf_clear( result1 ); 
  mpf_clear( result2 ); 
  mpf_clear( result3 ); 
  mpf_clears( xp, item, result, NULL );
}