import math



k=int(eval(input()))

ans=0

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

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

    aa=math.gcd(i,j)

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

      ans+=math.gcd(aa,l)



print(ans)
import math

from functools import reduce



k=int(eval(input()))



def gcd(*numbers):

    return reduce(math.gcd,numbers)



ans=0  

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

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

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

      ans+=gcd(i,j,l)



print(ans)
import math

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

import math
from functools import reduce

k = int(eval(input()))


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


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

+from functools import reduce + + +def gcd(*numbers): +    return reduce(math.gcd, numbers) + + -        aa = math.gcd(i, j) -            ans += math.gcd(aa, l) +            ans += gcd(i, j, l)