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

namespace C_ABC162
{
    class MainClass
    {

        static int[] s;
        static long[,] g = new long[201, 201];
        public static void Main(string[] args)
        {
            s = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);
            long sum = 0;
            for (int i = 1; i <= s[0]; i++)
            {
                for (int j = 1; j <= s[0]; j++)
                {
                    for (int k = 1; k <= s[0]; k++)
                    {
                        sum += Gcd(i, Gcd(j, k));



                    }
                }
            }

            WriteLine(sum);
        }
        public static long Gcd(long a, long b)
        {
            if (g[a, b] != 0)
            {
                return g[a, b];
            }
            long tmp;
            // a<bにする
            if (a >= b)
            {
                tmp = a;
                a = b;
                b = tmp;
            }

            if (a == 0)
            {
                g[a, b] = b;
                return b;
            }

            tmp = a;
            a = b % a;
            b = tmp;
            g[a, b] = Gcd(a, b);
            return g[a, b];

        }
    }
}
