function x = zipf_cdf_inv ( a, cdf )

%*****************************************************************************80
%
%% zipf_cdf_inv() inverts the Zipf CDF.
%
%  Discussion:
%
%    Simple summation is used.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    08 March 2016
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    real CDF, the value of the CDF.
%
%    real A, the parameter of the PDF.
%    1.0 < A.
%
%  Output:
%
%    integer X, the argument such that
%    CDF(X-1) < CDF <= CDF(X)
%    1 <= X <= 1000
%
  if ( cdf <= 0.0 )

    x = 1;

  else

    c = zeta ( a );
    cdf2 = 0.0;

    x = 1000;

    for y = 1 : 1000
      pdf = ( 1.0 / y ^ a ) / c;
      cdf2 = cdf2 + pdf;
      if ( cdf <= cdf2 )
        x = y;
        break;
      end
    end

  end

  return
end
