public static void moebius_test()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    MOEBIUS_TEST tests MOEBIUS.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    02 June 2007
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int c = 0;
        int n = 0;

        Console.WriteLine("");
        Console.WriteLine("MOEBIUS_TEST");
        Console.WriteLine("  MOEBIUS computes the Moebius function.");
        Console.WriteLine("");
        Console.WriteLine("      N   Exact   MOEBIUS(N)");
        Console.WriteLine("");

        int n_data = 0;

        for (;;)
        {
            Burkardt.Values.Moebius.moebius_values(ref n_data, ref n, ref c);

            if (n_data == 0)
            {
                break;
            }

            Console.WriteLine("  "
                              + n.ToString().PadLeft(8) + "  "
                              + c.ToString().PadLeft(10) + "  "
                              + Moebius.moebius(n).ToString().PadLeft(10) + "");
        }
    }
示例#2
0
    public static int mertens(int n)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    MERTENS evaluates the Mertens function.
    //
    //  Discussion:
    //
    //    The Mertens function M(N) is the sum from 1 to N of the Moebius
    //    function MU.  That is,
    //
    //    M(N) = sum ( 1 <= I <= N ) MU(I)
    //
    //        N   M(N)
    //        --  ----
    //         1     1
    //         2     0
    //         3    -1
    //         4    -1
    //         5    -2
    //         6    -1
    //         7    -2
    //         8    -2
    //         9    -2
    //        10    -1
    //        11    -2
    //        12    -2
    //       100     1
    //      1000     2
    //     10000   -23
    //    100000   -48
    //
    //    The determinant of the Redheffer matrix of order N is equal
    //    to the Mertens function M(N).
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    16 October 2007
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Reference:
    //
    //    M Deleglise, J Rivat,
    //    Computing the Summation of the Moebius Function,
    //    Experimental Mathematics,
    //    Volume 5, 1996, pages 291-295.
    //
    //    Eric Weisstein,
    //    CRC Concise Encyclopedia of Mathematics,
    //    CRC Press, 2002,
    //    Second edition,
    //    ISBN: 1584883472,
    //    LC: QA5.W45
    //
    //  Parameters:
    //
    //    Input, int N, the argument.
    //
    //    Output, int MERTENS, the value.
    //
    {
        int i;

        int value = 0;

        for (i = 1; i <= n; i++)
        {
            value += Moebius.moebius(i);
        }
        return(value);
    }