from math import gcd



K = int(eval(input()))

ans = 0



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

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

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

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

            

print(ans)
from math import *



K = int(eval(input()))

ans = 0



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

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

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

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



print(ans)
from math import gcd

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

from math import *

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

-from math import gcd +from math import *