import sys

import fractions



def in_ctrl():

    _input = [_.rstrip() for _ in sys.stdin.readlines()]

    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

    K = int(_input[0])

    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    return K





def out_ctrl(s):

    print(s)





if __name__ == "__main__":

    K = in_ctrl()

    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

    cnt = 0

    dict_ = {}

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

        cnt += a

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

            if '{}_{}'.format(a,b) in dict_:

                ans = dict_['{}_{}'.format(a,b)]

            else:

                ans = fractions.gcd(a,b)

                dict_['{}_{}'.format(a,b)] = ans

            cnt += 6*ans

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

                if '{}_{}'.format(ans,c) in dict_:

                    _ans = dict_['{}_{}'.format(ans,c)]

                else:

                    _ans = fractions.gcd(ans, c)

                    dict_['{}_{}'.format(ans,c)] = _ans

                cnt += 6*_ans

    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    out_ctrl(cnt)
from sys import stdin

from math import gcd





if __name__ == "__main__":

    _in = [_.rstrip() for _ in stdin.readlines()]

    K = int(_in[0])  # type:int

    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

    cnt = 0

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

        cnt += a

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

            ab = gcd(a,b)

            cnt += 6*ab

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

                cnt += 6*gcd(ab, c)

    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    print(cnt)

    
import sys
import fractions


def in_ctrl():
    _input = [_.rstrip() for _ in sys.stdin.readlines()]
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    K = int(_input[0])
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    return K


def out_ctrl(s):
    print(s)


if __name__ == "__main__":
    K = in_ctrl()
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    cnt = 0
    dict_ = {}
    for a in range(1, K + 1):
        cnt += a
        for b in range(a + 1, K + 1):
            if "{}_{}".format(a, b) in dict_:
                ans = dict_["{}_{}".format(a, b)]
            else:
                ans = fractions.gcd(a, b)
                dict_["{}_{}".format(a, b)] = ans
            cnt += 6 * ans
            for c in range(b + 1, K + 1):
                if "{}_{}".format(ans, c) in dict_:
                    _ans = dict_["{}_{}".format(ans, c)]
                else:
                    _ans = fractions.gcd(ans, c)
                    dict_["{}_{}".format(ans, c)] = _ans
                cnt += 6 * _ans
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    out_ctrl(cnt)

from sys import stdin
from math import gcd

if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    K = int(_in[0])  # type:int
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    cnt = 0
    for a in range(1, K + 1):
        cnt += a
        for b in range(a + 1, K + 1):
            ab = gcd(a, b)
            cnt += 6 * ab
            for c in range(b + 1, K + 1):
                cnt += 6 * gcd(ab, c)
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)

-import sys -import fractions - - -def in_ctrl(): -    _input = [_.rstrip() for _ in sys.stdin.readlines()] -    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv -    K = int(_input[0]) -    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -    return K - - -def out_ctrl(s): -    print(s) - +from sys import stdin +from math import gcd -    K = in_ctrl() +    _in = [_.rstrip() for _ in stdin.readlines()] +    K = int(_in[0])  # type:int -    dict_ = {} -            if "{}_{}".format(a, b) in dict_: -                ans = dict_["{}_{}".format(a, b)] -            else: -                ans = fractions.gcd(a, b) -                dict_["{}_{}".format(a, b)] = ans -            cnt += 6 * ans +            ab = gcd(a, b) +            cnt += 6 * ab -                if "{}_{}".format(ans, c) in dict_: -                    _ans = dict_["{}_{}".format(ans, c)] -                else: -                    _ans = fractions.gcd(ans, c) -                    dict_["{}_{}".format(ans, c)] = _ans -                cnt += 6 * _ans +                cnt += 6 * gcd(ab, c) -    out_ctrl(cnt) +    print(cnt)