from math import gcd

def main():

    ans = 0

    k = int(eval(input()))

    for i in range(k):

        for j in range(k):

            for l in range(k):

                ans += gcd(i+1,gcd(j+1,l+1))

    print(ans)





if __name__ == "__main__":

    main()
from math import gcd

def main():

    ans = 0

    k = int(eval(input()))

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

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

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

                ans += gcd(i,gcd(j,l))

    print(ans)





if __name__ == "__main__":

    main()
from math import gcd


def main():
    ans = 0
    k = int(eval(input()))
    for i in range(k):
        for j in range(k):
            for l in range(k):
                ans += gcd(i + 1, gcd(j + 1, l + 1))
    print(ans)


if __name__ == "__main__":
    main()

from math import gcd


def main():
    ans = 0
    k = int(eval(input()))
    for i in range(1, 1 + k):
        for j in range(1, 1 + k):
            for l in range(1, 1 + k):
                ans += gcd(i, gcd(j, l))
    print(ans)


if __name__ == "__main__":
    main()

-    for i in range(k): -        for j in range(k): -            for l in range(k): -                ans += gcd(i + 1, gcd(j + 1, l + 1)) +    for i in range(1, 1 + k): +        for j in range(1, 1 + k): +            for l in range(1, 1 + k): +                ans += gcd(i, gcd(j, l))