import math

n = int(eval(input()))

sum = 0

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

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

    g = math.gcd(i,j)

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

      sum += math.gcd(g,k)

print(sum)
import math

def main():

  n = int(eval(input()))

  sum = 0

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

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

      g = math.gcd(i,j)

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

        sum += math.gcd(g,k)

  print(sum)



if __name__ == "__main__":

  main()
import math

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

import math


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


if __name__ == "__main__":
    main()

-n = int(eval(input())) -sum = 0 -for i in range(1, n + 1): -    for j in range(1, n + 1): -        g = math.gcd(i, j) -        for k in range(1, n + 1): -            sum += math.gcd(g, k) -print(sum) + +def main(): +    n = int(eval(input())) +    sum = 0 +    for i in range(1, n + 1): +        for j in range(1, n + 1): +            g = math.gcd(i, j) +            for k in range(1, n + 1): +                sum += math.gcd(g, k) +    print(sum) + + +if __name__ == "__main__": +    main()