import math

k = int(eval(input()))

ans = 0



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

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

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

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

print(ans)
import math

k = int(eval(input()))

dec = {}



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

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

        if math.gcd(a, b) not in dec:

            dec[math.gcd(a,b)] = 1

        else:

            dec[math.gcd(a,b)] += 1

ans = 0

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

    for d in list(dec.keys()):

        ans += math.gcd(d, c) * dec[d]

print(ans)
import math

k = int(eval(input()))
ans = 0
for a in range(1, k + 1):
    for b in range(1, k + 1):
        for c in range(1, k + 1):
            ans += math.gcd(math.gcd(a, b), c)
print(ans)

import math

k = int(eval(input()))
dec = {}
for a in range(1, k + 1):
    for b in range(1, k + 1):
        if math.gcd(a, b) not in dec:
            dec[math.gcd(a, b)] = 1
        else:
            dec[math.gcd(a, b)] += 1
ans = 0
for c in range(1, k + 1):
    for d in list(dec.keys()):
        ans += math.gcd(d, c) * dec[d]
print(ans)

-ans = 0 +dec = {} -        for c in range(1, k + 1): -            ans += math.gcd(math.gcd(a, b), c) +        if math.gcd(a, b) not in dec: +            dec[math.gcd(a, b)] = 1 +        else: +            dec[math.gcd(a, b)] += 1 +ans = 0 +for c in range(1, k + 1): +    for d in list(dec.keys()): +        ans += math.gcd(d, c) * dec[d]