import math

from functools import reduce



def gcd(*numbers):

    return reduce(math.gcd, numbers)



k = int(eval(input()))

ans = 0



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

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

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

            ans += gcd(x,y,z)

            

print(ans)

k = int(eval(input()))

ans = 0



import math



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

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

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

            ans += math.gcd(i,math.gcd(j,k))

            

print(ans)
import math
from functools import reduce


def gcd(*numbers):
    return reduce(math.gcd, numbers)


k = int(eval(input()))
ans = 0
for x in range(1, k + 1):
    for y in range(1, k + 1):
        for z in range(1, k + 1):
            ans += gcd(x, y, z)
print(ans)

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

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

-import math -from functools import reduce - - -def gcd(*numbers): -    return reduce(math.gcd, numbers) - - -for x in range(1, k + 1): -    for y in range(1, k + 1): -        for z in range(1, k + 1): -            ans += gcd(x, y, z) +import math + +for i in range(1, k + 1): +    for j in range(1, k + 1): +        for k in range(1, k + 1): +            ans += math.gcd(i, math.gcd(j, k))