from  math import gcd

 

 

k = int(eval(input()))

sum_c = 0

 

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

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

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

            sum_c += gcd(gcd(a, b), c)

            

print(sum_c)
import math

A = int(eval(input()))

def gcd(A):

    total = 0

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

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

            B = math.gcd(i,j)

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

                total += math.gcd(B,k)

    return total

print((gcd(A)))
from math import gcd

k = int(eval(input()))
sum_c = 0
for a in range(1, k + 1):
    for b in range(1, k + 1):
        for c in range(1, k + 1):
            sum_c += gcd(gcd(a, b), c)
print(sum_c)

import math

A = int(eval(input()))


def gcd(A):
    total = 0
    for i in range(1, A + 1):
        for j in range(1, A + 1):
            B = math.gcd(i, j)
            for k in range(1, A + 1):
                total += math.gcd(B, k)
    return total


print((gcd(A)))

-from math import gcd +import math -k = int(eval(input())) -sum_c = 0 -for a in range(1, k + 1): -    for b in range(1, k + 1): -        for c in range(1, k + 1): -            sum_c += gcd(gcd(a, b), c) -print(sum_c) +A = int(eval(input())) + + +def gcd(A): +    total = 0 +    for i in range(1, A + 1): +        for j in range(1, A + 1): +            B = math.gcd(i, j) +            for k in range(1, A + 1): +                total += math.gcd(B, k) +    return total + + +print((gcd(A)))