from math import gcd



K = int(eval(input()))+1

ans = 0

for i in range(1,K):

    for j in range(1,K):

        for k in range(1,K):

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

print(ans)
from math import gcd



def solve():

    K = int(eval(input()))+1

    ans = 0

    for i in range(1,K):

        for j in range(1,K):

            for k in range(1,K):

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

    return ans



print((solve()))
from math import gcd

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

from math import gcd


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


print((solve()))

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