from math import factorial



from sys import stdin





def gcd(x, y):

    if x % y == 0:

        return y

    return gcd(y, x % y)





def main():

    k = int(stdin.readline())



    ans = 0



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

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

            d = gcd(a, b)

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

                e = gcd(d, c)

                ans += e * factorial(3) // factorial(3 - len(set([a, b, c])) + 1)



    print(ans)





if __name__ == "__main__":

    main()

from sys import stdin





def gcd(x, y):

    if x % y == 0:

        return y

    return gcd(y, x % y)





def fact(x):

    if x == 1:

        return x

    return x * fact(x - 1)





def main():

    k = int(stdin.readline())



    ans = 0



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

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

            d = gcd(a, b)

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

                e = gcd(d, c)

                ans += e * fact(3) // fact(3 - len(set([a, b, c])) + 1)



    print(ans)





if __name__ == "__main__":

    main()

from math import factorial
from sys import stdin


def gcd(x, y):
    if x % y == 0:
        return y
    return gcd(y, x % y)


def main():
    k = int(stdin.readline())
    ans = 0
    for a in range(1, k + 1):
        for b in range(a, k + 1):
            d = gcd(a, b)
            for c in range(b, k + 1):
                e = gcd(d, c)
                ans += e * factorial(3) // factorial(3 - len(set([a, b, c])) + 1)
    print(ans)


if __name__ == "__main__":
    main()

from sys import stdin


def gcd(x, y):
    if x % y == 0:
        return y
    return gcd(y, x % y)


def fact(x):
    if x == 1:
        return x
    return x * fact(x - 1)


def main():
    k = int(stdin.readline())
    ans = 0
    for a in range(1, k + 1):
        for b in range(a, k + 1):
            d = gcd(a, b)
            for c in range(b, k + 1):
                e = gcd(d, c)
                ans += e * fact(3) // fact(3 - len(set([a, b, c])) + 1)
    print(ans)


if __name__ == "__main__":
    main()

-from math import factorial + + +def fact(x): +    if x == 1: +        return x +    return x * fact(x - 1) -                ans += e * factorial(3) // factorial(3 - len(set([a, b, c])) + 1) +                ans += e * fact(3) // fact(3 - len(set([a, b, c])) + 1)