import math

from functools import reduce



k = int(eval(input()))





def gcd(a, b, c):

    return reduce(math.gcd, [a, b, c])





ans = 0

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

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

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

            ans += gcd(a, b, c)



print(ans)

import math

from functools import reduce



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 += reduce(math.gcd, [a, b, c])



print(ans)

import math
from functools import reduce

k = int(eval(input()))


def gcd(a, b, c):
    return reduce(math.gcd, [a, b, c])


ans = 0
for a in range(1, k + 1):
    for b in range(1, k + 1):
        for c in range(1, k + 1):
            ans += gcd(a, b, c)
print(ans)

import math
from functools import reduce

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 += reduce(math.gcd, [a, b, c])
print(ans)

- - -def gcd(a, b, c): -    return reduce(math.gcd, [a, b, c]) - - -            ans += gcd(a, b, c) +            ans += reduce(math.gcd, [a, b, c])