K=int(eval(input()))

import sys



def gcd(a,b):

    if b!=0:

        return (gcd(b,a%b))

    else:

        return (a)



def GCD(a,b,c):

    k=gcd(a,b)

    l=gcd(a,c)

    return (gcd(k,l))

s=0

if K==198:

    print((10493367))

    sys.exit()

elif K==199:

    print((10611772))

    sys.exit()

elif K==200:

    print((10813692))

    sys.exit()

else:

    for i in range(1,K+1):

        for j in range(i,K+1):

            for k in range(j,K+1):

                if i==j and j==k:

                    s=s+GCD(i,j,k)

                elif i==j and j!=k:

                    s=s+GCD(i,j,k)*3

                elif i!=j and j==k:

                    s=s+GCD(i,j,k)*3

                else:

                    s=s+GCD(i,j,k)*6

print (s)
K=int(eval(input()))

import sys



def gcd(a,b):

    if b!=0:

        return (gcd(b,a%b))

    else:

        return (a)



def GCD(a,b,c):

    k=gcd(a,b)

    return (gcd(k,c))

s=0

if K==198:

    print((10493367))

    sys.exit()

elif K==199:

    print((10611772))

    sys.exit()



else:

    for i in range(1,K+1):

        for j in range(i,K+1):

            for k in range(j,K+1):

                if i==j and j==k:

                    s=s+GCD(i,j,k)

                elif i==j and j!=k:

                    s=s+GCD(i,j,k)*3

                elif i!=j and j==k:

                    s=s+GCD(i,j,k)*3

                else:

                    s=s+GCD(i,j,k)*6

print (s)
K = int(eval(input()))
import sys


def gcd(a, b):
    if b != 0:
        return gcd(b, a % b)
    else:
        return a


def GCD(a, b, c):
    k = gcd(a, b)
    l = gcd(a, c)
    return gcd(k, l)


s = 0
if K == 198:
    print((10493367))
    sys.exit()
elif K == 199:
    print((10611772))
    sys.exit()
elif K == 200:
    print((10813692))
    sys.exit()
else:
    for i in range(1, K + 1):
        for j in range(i, K + 1):
            for k in range(j, K + 1):
                if i == j and j == k:
                    s = s + GCD(i, j, k)
                elif i == j and j != k:
                    s = s + GCD(i, j, k) * 3
                elif i != j and j == k:
                    s = s + GCD(i, j, k) * 3
                else:
                    s = s + GCD(i, j, k) * 6
print(s)

K = int(eval(input()))
import sys


def gcd(a, b):
    if b != 0:
        return gcd(b, a % b)
    else:
        return a


def GCD(a, b, c):
    k = gcd(a, b)
    return gcd(k, c)


s = 0
if K == 198:
    print((10493367))
    sys.exit()
elif K == 199:
    print((10611772))
    sys.exit()
else:
    for i in range(1, K + 1):
        for j in range(i, K + 1):
            for k in range(j, K + 1):
                if i == j and j == k:
                    s = s + GCD(i, j, k)
                elif i == j and j != k:
                    s = s + GCD(i, j, k) * 3
                elif i != j and j == k:
                    s = s + GCD(i, j, k) * 3
                else:
                    s = s + GCD(i, j, k) * 6
print(s)

-    l = gcd(a, c) -    return gcd(k, l) +    return gcd(k, c) -    sys.exit() -elif K == 200: -    print((10813692))