k = int(eval(input()))

import math

import fractions

ans = 0

e = 0

d = 0

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

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

        #e = math.gcd(a,b)

        e = fractions.gcd(a,b)

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

            #d = math.gcd(e,c)

            d = fractions.gcd(e,c)

            if a != b and b!= c and a!= c:

                ans+= d*6

            elif (a==b and a!=c) or (a==c and a!= b) or (b == c and a!= b):

                ans+= d*3

            else:

                ans+= d

print(ans)

k = int(eval(input()))

import math

import fractions

ans = 0

e = 0

d = 0

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

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

        e = math.gcd(a,b)

        #e = fractions.gcd(a,b)

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

            d = math.gcd(e,c)

            #d = fractions.gcd(e,c)

            if a != b and b!= c and a!= c:

                ans+= d*6

            elif (a==b and a!=c) or (a==c and a!= b) or (b == c and a!= b):

                ans+= d*3

            else:

                ans+= d

print(ans)

k = int(eval(input()))
import math
import fractions

ans = 0
e = 0
d = 0
for a in range(1, k + 1):
    for b in range(a, k + 1):
        # e = math.gcd(a,b)
        e = fractions.gcd(a, b)
        for c in range(b, k + 1):
            # d = math.gcd(e,c)
            d = fractions.gcd(e, c)
            if a != b and b != c and a != c:
                ans += d * 6
            elif (a == b and a != c) or (a == c and a != b) or (b == c and a != b):
                ans += d * 3
            else:
                ans += d
print(ans)

k = int(eval(input()))
import math
import fractions

ans = 0
e = 0
d = 0
for a in range(1, k + 1):
    for b in range(a, k + 1):
        e = math.gcd(a, b)
        # e = fractions.gcd(a,b)
        for c in range(b, k + 1):
            d = math.gcd(e, c)
            # d = fractions.gcd(e,c)
            if a != b and b != c and a != c:
                ans += d * 6
            elif (a == b and a != c) or (a == c and a != b) or (b == c and a != b):
                ans += d * 3
            else:
                ans += d
print(ans)

-        # e = math.gcd(a,b) -        e = fractions.gcd(a, b) +        e = math.gcd(a, b) +        # e = fractions.gcd(a,b) -            # d = math.gcd(e,c) -            d = fractions.gcd(e, c) +            d = math.gcd(e, c) +            # d = fractions.gcd(e,c)