namespace Test
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    public class Test
    {
        public static void Main(string[] args)
        {
            var t = new Test();
            var input = t.ReadInputOneLine();
            var ans = 0;

            for (var i = 1; i <= input; i++)
            {
                for (var j = 1; j <= input; j++)
                {
                    for (var k = 1; k <= input; k++)
                    {
                        var list = new List<int>();
                        list.Add(i);
                        list.Add(j);
                        list.Add(k);
                        ans += Gcd(list);
                    }
                }
            }
            Console.WriteLine(ans);
        }

        /// <summary>
        /// 2つの数の最小公倍数を求める
        /// Gcdメソッドに依存。
        /// </summary>
        /// <returns>最小公倍数</returns>
        public static int Lcm(int a, int b)
        {
            return a * b / Gcd(a, b);
        }

        /// <summary>
        /// 2つの数の最大公約数を求める
        /// </summary>
        /// <returns>最大公約数</returns>
        public static int Gcd(int a, int b)
        {
            var r = 0;
            //大きさ比べて入れ替え
            if (a < b)
            {
                var temp = a;
                a = b;
                b = temp;
            }

            r = a % b;
            while (r > 0)
            {
                a = b;
                b = r;
                r = a % b;
            }

            return b;
        }

        /// <summary>
        /// 複数の数の最小公倍数を求める
        /// Gcdメソッドに依存
        /// </summary>
        /// <returns>最小公倍数</returns>
        public static int Lcm(List<int> list)
        {
            var a = 0;
            var b = 0;
            var stack = new Stack<int>();
            var loopCount = 0;
            var lcm = 0;

            foreach (var val in list)
            {
                stack.Push(val);
            }

            loopCount = stack.Count;

            for (var i = 0; i < loopCount - 1; i++)
            {
                if (i == 0)
                {
                    a = stack.Pop();
                    b = stack.Pop();
                }
                else if (i > 0)
                {
                    a = lcm;
                    b = stack.Pop();
                }

                lcm = a * b / Gcd(a, b);
            }
            return lcm;
        }

        /// <summary>
        /// 複数の数の最大公約数を求める
        /// </summary>
        /// <returns>最大公約数</returns>
        public static int Gcd(List<int> list)
        {
            var a = 0;
            var b = 0;
            var r = 0;
            var stack = new Stack<int>();
            var loopCount = 0;

            foreach (var val in list)
            {
                stack.Push(val);
            }

            loopCount = stack.Count;
            for (var i = 0; i < loopCount - 1; i++)
            {
                if (i == 0)
                {
                    a = stack.Pop();
                    b = stack.Pop();
                }
                else if (i > 0)
                {
                    a = b;
                    b = stack.Pop();
                }

                //大きさ比べて入れ替え
                if (a < b)
                {
                    int temp = a;
                    a = b;
                    b = temp;
                }

                r = a % b;

                while (r > 0)
                {
                    a = b;
                    b = r;
                    r = a % b;
                }
            }
            return b;
        }
        public int ReadInputOneLine()
        {
            return int.Parse(Console.ReadLine());
        }

        public string[] ReadInput()
        {
            return Console.ReadLine().Split(' ');
        }

        public List<int> ParseIntList(string[] x)
        {
            var convertedList = new List<int>(x.Length);
            for (var i = 0; i < x.Length; i++)
            {
                convertedList.Add(int.Parse(x[i]));
            }

            return convertedList;
        }


        public List<double> ParseDoubleList(string[] x)
        {
            var convertedList = new List<double>(x.Length);
            for (var i = 0; i < x.Length; i++)
            {
                convertedList.Add(double.Parse(x[i]));
            }

            return convertedList;
        }

        public List<long> ParseLongList(string[] x)
        {
            var convertedList = new List<long>(x.Length);
            for (var i = 0; i < x.Length; i++)
            {
                convertedList.Add(long.Parse(x[i]));
            }

            return convertedList;
        }

        public int CountContainWords(string source, string word)
        {
            var count = 0;
            var loopCount = source.Length - (word.Length - 1);
            for (var i = 0; i < loopCount; i++)
            {
                if (source.Substring(i, word.Length) == word)
                {
                    count++;
                }
            }
            return count;
        }
    }
}

Measured memory_bytes: 21744