MOD = 10 ** 9 + 7

INF = 10 ** 12

import sys

sys.setrecursionlimit(100000000)

dy = (-1,0,1,0)

dx = (0,1,0,-1)

from  itertools import permutations

from math import gcd



def main():

    k = int(eval(input()))

    ans = 0

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

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

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

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

    print(ans)

if __name__ =='__main__':

    main()  
import numpy as np

k = int(eval(input()))

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

ans = np.gcd.outer(np.gcd.outer(a,a),a).sum()

print(ans)
MOD = 10**9 + 7
INF = 10**12
import sys

sys.setrecursionlimit(100000000)
dy = (-1, 0, 1, 0)
dx = (0, 1, 0, -1)
from itertools import permutations
from math import gcd


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


if __name__ == "__main__":
    main()

import numpy as np

k = int(eval(input()))
a = np.arange(1, k + 1)
ans = np.gcd.outer(np.gcd.outer(a, a), a).sum()
print(ans)

-MOD = 10**9 + 7 -INF = 10**12 -import sys +import numpy as np -sys.setrecursionlimit(100000000) -dy = (-1, 0, 1, 0) -dx = (0, 1, 0, -1) -from itertools import permutations -from math import gcd - - -def main(): -    k = int(eval(input())) -    ans = 0 -    for i in range(1, k + 1): -        for j in range(1, k + 1): -            for l in range(1, k + 1): -                ans += gcd(gcd(i, j), l) -    print(ans) - - -if __name__ == "__main__": -    main() +k = int(eval(input())) +a = np.arange(1, k + 1) +ans = np.gcd.outer(np.gcd.outer(a, a), a).sum() +print(ans)