import math



k = int(eval(input()))

sum = 0



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

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

        sum1 = math.gcd(i , j)

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

            sum += math.gcd(sum1, l)

print(sum)

import math



k = int(eval(input()))

sum = 0

ans = 0



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

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

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

            ans += math.gcd(math.gcd(a, b), c)



print(ans)
import math

k = int(eval(input()))
sum = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        sum1 = math.gcd(i, j)
        for l in range(1, k + 1):
            sum += math.gcd(sum1, l)
print(sum)

import math

k = int(eval(input()))
sum = 0
ans = 0
for a in range(1, k + 1):
    for b in range(1, k + 1):
        for c in range(1, k + 1):
            ans += math.gcd(math.gcd(a, b), c)
print(ans)

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