from math import gcd

from functools import lru_cache

from itertools import combinations



a = int(eval(input()))



def main():

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

        for j in range(i, a+1):

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

                x = len({i, j, k})

                if x == 1:

                    x = 1

                elif x == 2:

                    x = 3

                else:

                    x = 6

                yield gcd(gcd(i, j), k) * x



print((sum(main())))



from math import gcd



a = int(eval(input()))



def main():

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

        for j in range(i, a+1):

            ab = gcd(i, j)

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

                x = len({i, j, k})

                if x == 1:

                    x = 1

                elif x == 2:

                    x = 3

                else:

                    x = 6

                yield gcd(ab, k) * x



print((sum(main())))



from math import gcd
from functools import lru_cache
from itertools import combinations

a = int(eval(input()))


def main():
    for i in range(1, a + 1):
        for j in range(i, a + 1):
            for k in range(j, a + 1):
                x = len({i, j, k})
                if x == 1:
                    x = 1
                elif x == 2:
                    x = 3
                else:
                    x = 6
                yield gcd(gcd(i, j), k) * x


print((sum(main())))

from math import gcd

a = int(eval(input()))


def main():
    for i in range(1, a + 1):
        for j in range(i, a + 1):
            ab = gcd(i, j)
            for k in range(j, a + 1):
                x = len({i, j, k})
                if x == 1:
                    x = 1
                elif x == 2:
                    x = 3
                else:
                    x = 6
                yield gcd(ab, k) * x


print((sum(main())))

-from functools import lru_cache -from itertools import combinations +            ab = gcd(i, j) -                yield gcd(gcd(i, j), k) * x +                yield gcd(ab, k) * x