function [ n_data, n, p ] = pi_values ( n_data )

%*****************************************************************************80
%
%% pi_values() returns values of the Pi function.
%
%  Discussion:
%
%    Pi[n] is the number of primes less than or equal to n.
%
%    In Mathematica, the function can be evaluated by:
%
%      PrimePi[n]
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    31 December 2022
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Stephen Wolfram,
%    The Mathematica Book,
%    Fourth Edition,
%    Wolfram Media / Cambridge University Press, 1999.
%
%  Input:
%
%    integer N_DATA.  The user sets N_DATA to 0 before the first call.  
%    Thereafter, it should simply be the value returned by the previous call.
%
%  Output:
%
%    integer N_DATA.  On each call, the routine increments N_DATA by 1, and
%    returns the corresponding data; when there is no more data, the
%    output value of N_DATA will be 0 again.
%
%    integer N, the argument.
%
%    integer P, the value of the function.
%
  n_max = 21;

  n_vec = [ ...
            1, ...
            2, ...
            4, ...
            8, ...
           16, ...
           32, ...
           64, ...
          128, ...
          256, ...
          512, ...
         1024, ...
         2048, ...
         4096, ...
         8192, ...
        16384, ...
        32768, ...
        65536, ...
       131072, ...
       262144, ...
       524288, ...
      1048576 ];

  p_vec = [ ...
             0, ...
             1, ...
             2, ...
             4, ...
             6, ...
            11, ...
            18, ...
            31, ...
            54, ...
            97, ...
           172, ...
           309, ...
           564, ...
          1028, ...
          1900, ...
          3512, ...
          6542, ...
         12251, ...
         23000, ...
         43390, ...
         82025  ];

  if ( n_data < 0 )
    n_data = 0;
  end

  n_data = n_data + 1;

  if ( n_max < n_data )
    n_data = 0;
    n = 0;
    p = 0;
  else
    n = n_vec(n_data);
    p = p_vec(n_data);
  end

  return
end
