n = int(eval(input()))

import math

from fractions import gcd

s = 0

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

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

		x = math.gcd(i,j)

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

			s += math.gcd(x,k)

print (s)
from math import gcd

n = int(eval(input()))

s = 0

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

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

		x = gcd(i,j)

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

			s += gcd(x,k)

print (s)
n = int(eval(input()))
import math
from fractions import gcd

s = 0
for i in range(1, n + 1):
    for j in range(1, n + 1):
        x = math.gcd(i, j)
        for k in range(1, n + 1):
            s += math.gcd(x, k)
print(s)

from math import gcd

n = int(eval(input()))
s = 0
for i in range(1, n + 1):
    for j in range(1, n + 1):
        x = gcd(i, j)
        for k in range(1, n + 1):
            s += gcd(x, k)
print(s)

+from math import gcd + -import math -from fractions import gcd - -        x = math.gcd(i, j) +        x = gcd(i, j) -            s += math.gcd(x, k) +            s += gcd(x, k)