from math import gcd

from functools import reduce

 

k=int(eval(input()))

z=list(range(1,k+1))

print((sum([gcd(i,gcd(j,k)) for i in z for j in z for k in z])))

from math import gcd

from functools import reduce

 

k=int(eval(input()))

z=list(range(1,k+1))

print((sum(gcd(i,gcd(j,k)) for i in z for j in z for k in z)))

from math import gcd
from functools import reduce

k = int(eval(input()))
z = list(range(1, k + 1))
print((sum([gcd(i, gcd(j, k)) for i in z for j in z for k in z])))

from math import gcd
from functools import reduce

k = int(eval(input()))
z = list(range(1, k + 1))
print((sum(gcd(i, gcd(j, k)) for i in z for j in z for k in z)))

-print((sum([gcd(i, gcd(j, k)) for i in z for j in z for k in z]))) +print((sum(gcd(i, gcd(j, k)) for i in z for j in z for k in z)))