from math import gcd 

K=int(eval(input()))



s=0



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

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

        a=gcd(i,j)

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

            s+=gcd(a,k)



print(s)

from math import gcd 

K=int(eval(input()))



A=[0]*K



for i in range(K,0,-1):

    b=pow(K//i,3)

    A[i-1]=b



for i in range(K,0,-1):

    for j in range(K//i-1):

        c=i*(j+2)

        A[i-1]-=A[c-1]



s=0

for i in range(K):

    s+=A[i]*(i+1)



print(s)
from math import gcd

K = int(eval(input()))
s = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        a = gcd(i, j)
        for k in range(1, K + 1):
            s += gcd(a, k)
print(s)

from math import gcd

K = int(eval(input()))
A = [0] * K
for i in range(K, 0, -1):
    b = pow(K // i, 3)
    A[i - 1] = b
for i in range(K, 0, -1):
    for j in range(K // i - 1):
        c = i * (j + 2)
        A[i - 1] -= A[c - 1]
s = 0
for i in range(K):
    s += A[i] * (i + 1)
print(s)

+A = [0] * K +for i in range(K, 0, -1): +    b = pow(K // i, 3) +    A[i - 1] = b +for i in range(K, 0, -1): +    for j in range(K // i - 1): +        c = i * (j + 2) +        A[i - 1] -= A[c - 1] -for i in range(1, K + 1): -    for j in range(1, K + 1): -        a = gcd(i, j) -        for k in range(1, K + 1): -            s += gcd(a, k) +for i in range(K): +    s += A[i] * (i + 1)