from functools import lru_cache



@lru_cache(maxsize=100000)

def gcd(a, b):

    while b:

        a, b = b, a % b

    return a





def resolve():

    k = int(eval(input()))

    l = [None] * k ** 2

    for i in range(k):

        for j in range(k):

            l[i * k + j] = gcd(i + 1, j + 1)

    ans = 0

    for i in l:

        for j in range(k):

            ans += gcd(i, j + 1)

    print(ans)





if __name__ == '__main__':

    resolve()

from math import gcd



def resolve():

    k = int(eval(input()))

    l = [None] * k ** 2

    for i in range(k):

        for j in range(k):

            l[i * k + j] = gcd(i + 1, j + 1)

    ans = 0

    for i in l:

        for j in range(k):

            ans += gcd(i, j + 1)

    print(ans)





if __name__ == '__main__':

    resolve()

from functools import lru_cache


@lru_cache(maxsize=100000)
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def resolve():
    k = int(eval(input()))
    l = [None] * k**2
    for i in range(k):
        for j in range(k):
            l[i * k + j] = gcd(i + 1, j + 1)
    ans = 0
    for i in l:
        for j in range(k):
            ans += gcd(i, j + 1)
    print(ans)


if __name__ == "__main__":
    resolve()

from math import gcd


def resolve():
    k = int(eval(input()))
    l = [None] * k**2
    for i in range(k):
        for j in range(k):
            l[i * k + j] = gcd(i + 1, j + 1)
    ans = 0
    for i in l:
        for j in range(k):
            ans += gcd(i, j + 1)
    print(ans)


if __name__ == "__main__":
    resolve()

-from functools import lru_cache - - -@lru_cache(maxsize=100000) -def gcd(a, b): -    while b: -        a, b = b, a % b -    return a +from math import gcd