k=int(eval(input()))

import math

ans=0

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

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

        a=math.gcd(i,j)

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

            ans+=math.gcd(a,l)

print(ans)
k=int(eval(input()))

import math

ans=0

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

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

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

        	a=math.gcd(i,j)

        	ans+=math.gcd(a,l)

print(ans)
k = int(eval(input()))
import math

ans = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        a = math.gcd(i, j)
        for l in range(1, k + 1):
            ans += math.gcd(a, l)
print(ans)

k = int(eval(input()))
import math

ans = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        for l in range(1, k + 1):
            a = math.gcd(i, j)
            ans += math.gcd(a, l)
print(ans)

-        a = math.gcd(i, j) +            a = math.gcd(i, j)