import math

from functools import reduce

K = int(eval(input()))

CNT= 0

def gcd(*numbers):

    return reduce(math.gcd, numbers)

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

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

        GCD = gcd(i,j)

        if GCD == 1:

            CNT += K

        else:

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

                if gcd(GCD,k) != 1:

                    CNT += gcd(GCD,k)

                else:

                    CNT += 1

print(CNT)
import math

from functools import reduce

K = int(eval(input()))

CNT= 0

def gcd(*numbers):

    return reduce(math.gcd, numbers)

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

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

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

            CNT += gcd(i,j,k)

print(CNT)
import math
from functools import reduce

K = int(eval(input()))
CNT = 0


def gcd(*numbers):
    return reduce(math.gcd, numbers)


for i in range(1, K + 1):
    for j in range(1, K + 1):
        GCD = gcd(i, j)
        if GCD == 1:
            CNT += K
        else:
            for k in range(1, K + 1):
                if gcd(GCD, k) != 1:
                    CNT += gcd(GCD, k)
                else:
                    CNT += 1
print(CNT)

import math
from functools import reduce

K = int(eval(input()))
CNT = 0


def gcd(*numbers):
    return reduce(math.gcd, numbers)


for i in range(1, K + 1):
    for j in range(1, K + 1):
        for k in range(1, K + 1):
            CNT += gcd(i, j, k)
print(CNT)

-        GCD = gcd(i, j) -        if GCD == 1: -            CNT += K -        else: -            for k in range(1, K + 1): -                if gcd(GCD, k) != 1: -                    CNT += gcd(GCD, k) -                else: -                    CNT += 1 +        for k in range(1, K + 1): +            CNT += gcd(i, j, k)