from fractions import gcd

k = int(eval(input()))



ans = 0



lst = [[0 for _ in range(1, k+1)] for __ in range(k+1)]

cnt = [0 for _ in range(1, k+1)]





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

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

        lst[i-1][j-1] = [gcd(i, j)]

        cnt[gcd(i, j)-1] += 1



ans = 0



for i in range(k):

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

        ans += cnt[i]*gcd((i+1),j)



print(ans)

from math import gcd

k = int(eval(input()))



ans = 0



lst = [[0 for _ in range(1, k+1)] for __ in range(k+1)]

cnt = [0 for _ in range(1, k+1)]





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

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

        tmp = gcd(i,j)

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

            ans += gcd(tmp,l)

            

print(ans)

from fractions import gcd

k = int(eval(input()))
ans = 0
lst = [[0 for _ in range(1, k + 1)] for __ in range(k + 1)]
cnt = [0 for _ in range(1, k + 1)]
for i in range(1, k + 1):
    for j in range(1, k + 1):
        lst[i - 1][j - 1] = [gcd(i, j)]
        cnt[gcd(i, j) - 1] += 1
ans = 0
for i in range(k):
    for j in range(1, k + 1):
        ans += cnt[i] * gcd((i + 1), j)
print(ans)

from math import gcd

k = int(eval(input()))
ans = 0
lst = [[0 for _ in range(1, k + 1)] for __ in range(k + 1)]
cnt = [0 for _ in range(1, k + 1)]
for i in range(1, k + 1):
    for j in range(1, k + 1):
        tmp = gcd(i, j)
        for l in range(1, k + 1):
            ans += gcd(tmp, l)
print(ans)

-from fractions import gcd +from math import gcd -        lst[i - 1][j - 1] = [gcd(i, j)] -        cnt[gcd(i, j) - 1] += 1 -ans = 0 -for i in range(k): -    for j in range(1, k + 1): -        ans += cnt[i] * gcd((i + 1), j) +        tmp = gcd(i, j) +        for l in range(1, k + 1): +            ans += gcd(tmp, l)