from math import gcd

ans = 0

n = int(eval(input()))



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

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

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

            l = gcd(i,j)

            ans += gcd(k,l)

print(ans)
import math

ans = 0

n = int(eval(input()))



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

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

        l = math.gcd(i,j)

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

            ans += math.gcd(k,l)

print(ans)
from math import gcd

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

import math

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

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