k=int(eval(input()))

sum=0



def gcd(x,y):

  while y!=0:

    x,y=y,x%y

  return x

    

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

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

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

      sum+=gcd(i,gcd(j,z))

      

print(sum)
import math

k=int(eval(input()))

sum=0

    

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

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

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

      sum+=math.gcd(i,math.gcd(j,z))

      

print(sum)
k = int(eval(input()))
sum = 0


def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x


for i in range(1, k + 1):
    for j in range(1, k + 1):
        for z in range(1, k + 1):
            sum += gcd(i, gcd(j, z))
print(sum)

import math

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

+import math + - - -def gcd(x, y): -    while y != 0: -        x, y = y, x % y -    return x - - -            sum += gcd(i, gcd(j, z)) +            sum += math.gcd(i, math.gcd(j, z))