def main():

    k = int(eval(input()))

    gcds = list(sorted([gcd(i, j) for i in range(1, k+1) for j in range(1, k+1)]))

    j = 0

    s = list(sorted(list(set(gcds))))

    m = k**2-1

    gcdss = [0]*len(s)

    flag = False

    for i, l in enumerate(s):

        while gcds[j] == l:

            gcdss[i] += 1

            if j == m:

                flag = True

                break

            j += 1

        if flag:

            break

    ans = sum([gcd(i, p)*n for i in range(1, k+1) for p, n in zip(s, gcdss)])

    print(ans)

            

    

def gcd(a, b):

    if a < b:

        a, b = b, a

    if a % b == 0:

        return b

    else:

        return gcd(b, a%b)





if __name__ == "__main__":

    main()

def main():

    k = int(eval(input()))

    gcds = []

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

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

            gcds.append(gcd(i, j))

    ans = {i:0 for i in set(gcds)}

    for i in gcds:

        ans[i] += 1

    out = 0

    for i, v in list(ans.items()):

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

            out += gcd(i, j)*v

    print(out)



def gcd(x, y):

    r = x % y

    while r:

        x, y, r = y, r, y%r

    return y



if __name__ == "__main__":

    main()
def main():
    k = int(eval(input()))
    gcds = list(sorted([gcd(i, j) for i in range(1, k + 1) for j in range(1, k + 1)]))
    j = 0
    s = list(sorted(list(set(gcds))))
    m = k**2 - 1
    gcdss = [0] * len(s)
    flag = False
    for i, l in enumerate(s):
        while gcds[j] == l:
            gcdss[i] += 1
            if j == m:
                flag = True
                break
            j += 1
        if flag:
            break
    ans = sum([gcd(i, p) * n for i in range(1, k + 1) for p, n in zip(s, gcdss)])
    print(ans)


def gcd(a, b):
    if a < b:
        a, b = b, a
    if a % b == 0:
        return b
    else:
        return gcd(b, a % b)


if __name__ == "__main__":
    main()

def main():
    k = int(eval(input()))
    gcds = []
    for i in range(1, k + 1):
        for j in range(1, k + 1):
            gcds.append(gcd(i, j))
    ans = {i: 0 for i in set(gcds)}
    for i in gcds:
        ans[i] += 1
    out = 0
    for i, v in list(ans.items()):
        for j in range(1, k + 1):
            out += gcd(i, j) * v
    print(out)


def gcd(x, y):
    r = x % y
    while r:
        x, y, r = y, r, y % r
    return y


if __name__ == "__main__":
    main()

-    gcds = list(sorted([gcd(i, j) for i in range(1, k + 1) for j in range(1, k + 1)])) -    j = 0 -    s = list(sorted(list(set(gcds)))) -    m = k**2 - 1 -    gcdss = [0] * len(s) -    flag = False -    for i, l in enumerate(s): -        while gcds[j] == l: -            gcdss[i] += 1 -            if j == m: -                flag = True -                break -            j += 1 -        if flag: -            break -    ans = sum([gcd(i, p) * n for i in range(1, k + 1) for p, n in zip(s, gcdss)]) -    print(ans) +    gcds = [] +    for i in range(1, k + 1): +        for j in range(1, k + 1): +            gcds.append(gcd(i, j)) +    ans = {i: 0 for i in set(gcds)} +    for i in gcds: +        ans[i] += 1 +    out = 0 +    for i, v in list(ans.items()): +        for j in range(1, k + 1): +            out += gcd(i, j) * v +    print(out) -def gcd(a, b): -    if a < b: -        a, b = b, a -    if a % b == 0: -        return b -    else: -        return gcd(b, a % b) +def gcd(x, y): +    r = x % y +    while r: +        x, y, r = y, r, y % r +    return y