import sys

read = sys.stdin.read

readlines = sys.stdin.readlines

from math import gcd

def main():

    k = int(eval(input()))

    r = 0

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

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

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

                t1 = gcd(i1, i2)

                r += gcd(t1, i3)

    print(r)



if __name__ == '__main__':

    main()
import sys

read = sys.stdin.read

readlines = sys.stdin.readlines

import numpy as np

def main():

    k = int(eval(input()))



    k2 = np.arange(1, k+1)

    k2gcd = np.gcd.outer(k2, np.gcd.outer(k2, k2))

    print((k2gcd.sum()))



if __name__ == '__main__':

    main()
import sys

read = sys.stdin.read
readlines = sys.stdin.readlines
from math import gcd


def main():
    k = int(eval(input()))
    r = 0
    for i1 in range(1, k + 1):
        for i2 in range(1, k + 1):
            for i3 in range(1, k + 1):
                t1 = gcd(i1, i2)
                r += gcd(t1, i3)
    print(r)


if __name__ == "__main__":
    main()

import sys

read = sys.stdin.read
readlines = sys.stdin.readlines
import numpy as np


def main():
    k = int(eval(input()))
    k2 = np.arange(1, k + 1)
    k2gcd = np.gcd.outer(k2, np.gcd.outer(k2, k2))
    print((k2gcd.sum()))


if __name__ == "__main__":
    main()

-from math import gcd +import numpy as np -    r = 0 -    for i1 in range(1, k + 1): -        for i2 in range(1, k + 1): -            for i3 in range(1, k + 1): -                t1 = gcd(i1, i2) -                r += gcd(t1, i3) -    print(r) +    k2 = np.arange(1, k + 1) +    k2gcd = np.gcd.outer(k2, np.gcd.outer(k2, k2)) +    print((k2gcd.sum()))