using System;
using System.Linq;
using System.Collections.Generic;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var k = int.Parse(Console.ReadLine());

        var sum = 0;
        for (int a = 0; a < k; ++a)
        for (int b = 0; b < k; ++b)
        for (int c = 0; c < k; ++c)
        {
            sum += FindGcd(FindGcd(a + 1, b + 1), c + 1);
        }

        Console.WriteLine(sum);
    }

    public static int FindGcd(int x, int y, int k = 0) => x < 1 ? y : FindGcd(y % x, x, k + 1);
}
