import math



def resolve():

    N = int(input())

    ans = 0

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

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

            g = math.gcd(i, j)

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

                ans += math.gcd(g,k)



    return print(ans)



if __name__ == "__main__":

    resolve()

import numpy as np



def resolve():

    N = int(input())

    A = np.arange(1, N+1)

    ans = np.gcd.outer(np.gcd.outer(A, A),A)

    return print((ans.sum()))



if __name__ == "__main__":

    resolve()

import math


def resolve():
    N = int(input())
    ans = 0
    for i in range(1, N + 1):
        for j in range(1, N + 1):
            g = math.gcd(i, j)
            for k in range(1, N + 1):
                ans += math.gcd(g, k)
    return print(ans)


if __name__ == "__main__":
    resolve()

import numpy as np


def resolve():
    N = int(input())
    A = np.arange(1, N + 1)
    ans = np.gcd.outer(np.gcd.outer(A, A), A)
    return print((ans.sum()))


if __name__ == "__main__":
    resolve()

-import math +import numpy as np -    ans = 0 -    for i in range(1, N + 1): -        for j in range(1, N + 1): -            g = math.gcd(i, j) -            for k in range(1, N + 1): -                ans += math.gcd(g, k) -    return print(ans) +    A = np.arange(1, N + 1) +    ans = np.gcd.outer(np.gcd.outer(A, A), A) +    return print((ans.sum()))