using System;
using static System.Console;
using static System.Int32;
using static System.Math;
using System.Linq;
using System.Collections.Generic;

class Solution
{
    static void Main()
    {
    lb:
        var k = Parse(ReadLine());
        int r = 0;
        for(int a = 1; a <= k; ++a)
        {
            for(int b = 1; b <= k; ++b)
            {
                for(int c = 1; c <= k; ++c)
                {
                    r += gcb(a, b, c);
                }
            }
        }
        WriteLine(r);
    }

    static int gcb(int a, int b, int c) => gcb(gcb(a, b), c);
    static int gcb(int a, int b)
    {
        if (a < b) (b, a) = (a, b);
        while (true)
        {
            var jy = a % b;
            if (jy == 0) return b;
            (a, b) = (b, jy);
        }
    }
}
