from math import gcd



k=int(eval(input()))

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,gcd(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):

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

            ans+=(math.gcd(i,math.gcd(j,l)))

print(ans)
from math import gcd

k = int(eval(input()))
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, gcd(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):
        for l in range(1, k + 1):
            ans += math.gcd(i, math.gcd(j, l))
print(ans)

-from math import gcd +import math -            ans += gcd(i, gcd(j, l)) +            ans += math.gcd(i, math.gcd(j, l))