#!/usr/bin/env python3



from numba import njit



def main():

    k = int(eval(input()))

    print((getresult(k)))



@njit

def getresult(k):

    res = 0

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

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

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

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

    return res



@njit("i4(i4, i4)", cache=True)

def gcd(x, y):

    if x < y:

        x, y = y, x  # x >= y

    while y > 0:

        r = x % y

        x = y

        y = r

    return x



if __name__ == "__main__":

    main()

#!/usr/bin/env python3



import numpy as np

from numba import njit



def main():

    k = int(eval(input()))

    print((getresult(k)))



@njit("i4(i4, i4)", cache=True)

def gcd(x, y):

    if x < y:

        x, y = y, x  # x >= y

    while y > 0:

        r = x % y

        x = y

        y = r

    return x



@njit("i8(i4)", cache=True)

def getresult(k):

    res = np.array([0], dtype=np.int64)

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

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

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

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

    return res[0]



if __name__ == "__main__":

    main()

#!/usr/bin/env python3
from numba import njit


def main():
    k = int(eval(input()))
    print((getresult(k)))


@njit
def getresult(k):
    res = 0
    for a in range(1, k + 1):
        for b in range(1, k + 1):
            for c in range(1, k + 1):
                res += gcd(gcd(a, b), c)
    return res


@njit("i4(i4, i4)", cache=True)
def gcd(x, y):
    if x < y:
        x, y = y, x  # x >= y
    while y > 0:
        r = x % y
        x = y
        y = r
    return x


if __name__ == "__main__":
    main()

#!/usr/bin/env python3
import numpy as np
from numba import njit


def main():
    k = int(eval(input()))
    print((getresult(k)))


@njit("i4(i4, i4)", cache=True)
def gcd(x, y):
    if x < y:
        x, y = y, x  # x >= y
    while y > 0:
        r = x % y
        x = y
        y = r
    return x


@njit("i8(i4)", cache=True)
def getresult(k):
    res = np.array([0], dtype=np.int64)
    for a in range(1, k + 1):
        for b in range(1, k + 1):
            for c in range(1, k + 1):
                res += gcd(gcd(a, b), c)
    return res[0]


if __name__ == "__main__":
    main()

+import numpy as np - - -@njit -def getresult(k): -    res = 0 -    for a in range(1, k + 1): -        for b in range(1, k + 1): -            for c in range(1, k + 1): -                res += gcd(gcd(a, b), c) -    return res +@njit("i8(i4)", cache=True) +def getresult(k): +    res = np.array([0], dtype=np.int64) +    for a in range(1, k + 1): +        for b in range(1, k + 1): +            for c in range(1, k + 1): +                res += gcd(gcd(a, b), c) +    return res[0] + +