import math



k = int(eval(input()))

def ans():

    sum = 0

    temp = 0

    for l in range(1,k+1):

        for m in range(1,k+1):

            temp = math.gcd(l,m)

            for n in range(1,k+1):

                sum += math.gcd(temp,n)

    return(sum)

print((ans()))
import math

from numba import jit



k = int(eval(input()))



@jit

def ans():

    sum = 0

    temp = 0

    for l in range(1,k+1):

        for m in range(1,k+1):

            temp = math.gcd(l,m)

            for n in range(1,k+1):

                sum += math.gcd(temp,n)

    return(sum)

print((ans()))
import math

k = int(eval(input()))


def ans():
    sum = 0
    temp = 0
    for l in range(1, k + 1):
        for m in range(1, k + 1):
            temp = math.gcd(l, m)
            for n in range(1, k + 1):
                sum += math.gcd(temp, n)
    return sum


print((ans()))

import math
from numba import jit

k = int(eval(input()))


@jit
def ans():
    sum = 0
    temp = 0
    for l in range(1, k + 1):
        for m in range(1, k + 1):
            temp = math.gcd(l, m)
            for n in range(1, k + 1):
                sum += math.gcd(temp, n)
    return sum


print((ans()))

+from numba import jit +@jit