import math

k = int(eval(input()))

total = 0

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

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

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

            ab = math.gcd(a,b)

            total += math.gcd(ab, c)

print(total)

from math import gcd



k = int(eval(input()))



total = 0

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

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

        tmp = gcd(i,j)

        total += tmp * 6

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

            total += gcd(tmp,m) * 6

total += k*(k+1)//2



print(total)

import math

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

from math import gcd

k = int(eval(input()))
total = 0
for i in range(1, k + 1):
    for j in range(i + 1, k + 1):
        tmp = gcd(i, j)
        total += tmp * 6
        for m in range(j + 1, k + 1):
            total += gcd(tmp, m) * 6
total += k * (k + 1) // 2
print(total)

-import math +from math import gcd -for a in range(1, k + 1): -    for b in range(1, k + 1): -        for c in range(1, k + 1): -            ab = math.gcd(a, b) -            total += math.gcd(ab, c) +for i in range(1, k + 1): +    for j in range(i + 1, k + 1): +        tmp = gcd(i, j) +        total += tmp * 6 +        for m in range(j + 1, k + 1): +            total += gcd(tmp, m) * 6 +total += k * (k + 1) // 2