K=int(eval(input()))



import itertools,math

from functools import reduce



data = [i for i in range(1,K+1)]



def gcd(*numbers):

    return reduce(math.gcd, numbers)



ans = 0

for a,b,c in itertools.product(data, repeat=3):

    ans += gcd(a,b,c)

print(ans)



K=int(eval(input()))



import math

from functools import reduce



def gcd(*numbers):

    return reduce(math.gcd, numbers)

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)



K = int(eval(input()))
import itertools, math
from functools import reduce

data = [i for i in range(1, K + 1)]


def gcd(*numbers):
    return reduce(math.gcd, numbers)


ans = 0
for a, b, c in itertools.product(data, repeat=3):
    ans += gcd(a, b, c)
print(ans)

K = int(eval(input()))
import math
from functools import reduce


def gcd(*numbers):
    return reduce(math.gcd, numbers)


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 itertools, math +import math - -data = [i for i in range(1, K + 1)] -for a, b, c in itertools.product(data, repeat=3): -    ans += gcd(a, b, c) +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)