from sys import stdin

from math import gcd

def main():

    #入力

    readline=stdin.readline

    k=int(readline())

    ans=0

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

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

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

                ans+=gcd(a,gcd(b,c))



    print(ans)

if __name__=="__main__":

    main()
from sys import stdin

import numpy as np

def main():

    #入力

    readline=stdin.readline

    k=int(readline())



    a=np.arange(1,k+1,dtype=np.int64)

    b=np.gcd.outer(np.gcd.outer(a,a),a)

    print((b.sum()))



if __name__=="__main__":

    main()
from sys import stdin
from math import gcd


def main():
    # 入力
    readline = stdin.readline
    k = int(readline())
    ans = 0
    for a in range(1, k + 1):
        for b in range(1, k + 1):
            for c in range(1, k + 1):
                ans += gcd(a, gcd(b, c))
    print(ans)


if __name__ == "__main__":
    main()

from sys import stdin
import numpy as np


def main():
    # 入力
    readline = stdin.readline
    k = int(readline())
    a = np.arange(1, k + 1, dtype=np.int64)
    b = np.gcd.outer(np.gcd.outer(a, a), a)
    print((b.sum()))


if __name__ == "__main__":
    main()

-from math import gcd +import numpy as np -    ans = 0 -    for a in range(1, k + 1): -        for b in range(1, k + 1): -            for c in range(1, k + 1): -                ans += gcd(a, gcd(b, c)) -    print(ans) +    a = np.arange(1, k + 1, dtype=np.int64) +    b = np.gcd.outer(np.gcd.outer(a, a), a) +    print((b.sum()))