#!/usr/bin/env python3

import math

MOD = 10**9

def make_divisors(n):

    divisors = []

    for i in range(1, int(n**0.5)+1):

        if n % i == 0:

            divisors.append(i)

            if i != n // i:

                divisors.append(n//i)

    return divisors



K = int(eval(input()))



ans = 0

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

    for j in range(i, K+1):

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

            if i==j and i==k: g = i

            elif (i==j and i!=k):

                g = math.gcd(i,math.gcd(j,k))*3

            elif (i==k and i!=j):

                g = math.gcd(i,math.gcd(j,k))*3

            elif (j==k and i!=j):

                g = math.gcd(i,math.gcd(j,k))*3

            else : g = math.gcd(i,math.gcd(j,k))*6

            ans += g

print(ans)

import math



K = int(eval(input()))



ans = 0

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

    for j in range(i, K+1):

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

            if i==j and i==k: g = i

            elif (i==j and i!=k):

                g = math.gcd(i,math.gcd(j,k))*3

            elif (i==k and i!=j):

                g = math.gcd(i,math.gcd(j,k))*3

            elif (j==k and i!=j):

                g = math.gcd(i,math.gcd(j,k))*3

            else : g = math.gcd(i,math.gcd(j,k))*6

            ans += g

print(ans)

#!/usr/bin/env python3
import math

MOD = 10**9


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
    return divisors


K = int(eval(input()))
ans = 0
for i in range(1, K + 1):
    for j in range(i, K + 1):
        for k in range(j, K + 1):
            if i == j and i == k:
                g = i
            elif i == j and i != k:
                g = math.gcd(i, math.gcd(j, k)) * 3
            elif i == k and i != j:
                g = math.gcd(i, math.gcd(j, k)) * 3
            elif j == k and i != j:
                g = math.gcd(i, math.gcd(j, k)) * 3
            else:
                g = math.gcd(i, math.gcd(j, k)) * 6
            ans += g
print(ans)

import math

K = int(eval(input()))
ans = 0
for i in range(1, K + 1):
    for j in range(i, K + 1):
        for k in range(j, K + 1):
            if i == j and i == k:
                g = i
            elif i == j and i != k:
                g = math.gcd(i, math.gcd(j, k)) * 3
            elif i == k and i != j:
                g = math.gcd(i, math.gcd(j, k)) * 3
            elif j == k and i != j:
                g = math.gcd(i, math.gcd(j, k)) * 3
            else:
                g = math.gcd(i, math.gcd(j, k)) * 6
            ans += g
print(ans)

-#!/usr/bin/env python3 - -MOD = 10**9 - - -def make_divisors(n): -    divisors = [] -    for i in range(1, int(n**0.5) + 1): -        if n % i == 0: -            divisors.append(i) -            if i != n // i: -                divisors.append(n // i) -    return divisors -