import sys



input = sys.stdin.readline

from itertools import *

from functools import *

from collections import *

from heapq import heapify, heappop, heappush, heappushpop



# from math import gcd





def gcd(a, b):

    """

    Greatest Common Divisor

    Euclidean Algortihm

    """

    if a < b:

        gcd(b, a)

    while b != 0:

        a, b = b, a % b

    return a





INF = float('inf')

NIL = - 1



N = int(eval(input()))

ans = 0

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

    if i == 1:

        ans += N ** 2

        continue

    for j in range(1, N + 1):

        if j == 1:

            ans += N

            continue

        tmp = gcd(i, j)

        if tmp == 1:

            ans += N

            continue

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

            if k == 1:

                ans += 1

                continue

            ans += gcd(tmp, k)



print(ans)

import sys

sys.setrecursionlimit(10 ** 9)

input = sys.stdin.readline

from itertools import permutations,  combinations, accumulate

from functools import *

from collections import deque, defaultdict, Counter

from heapq import heapify, heappop, heappush, heappushpop

from math import gcd



INF = float('inf')

NIL = - 1





K = int(eval(input()))



total = 0

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

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

        tmp = gcd(a, b)

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

            total += gcd(tmp, c)



print(total)

import sys

input = sys.stdin.readline
from itertools import *
from functools import *
from collections import *
from heapq import heapify, heappop, heappush, heappushpop

# from math import gcd
def gcd(a, b):
    """
    Greatest Common Divisor
    Euclidean Algortihm
    """
    if a < b:
        gcd(b, a)
    while b != 0:
        a, b = b, a % b
    return a


INF = float("inf")
NIL = -1
N = int(eval(input()))
ans = 0
for i in range(1, N + 1):
    if i == 1:
        ans += N**2
        continue
    for j in range(1, N + 1):
        if j == 1:
            ans += N
            continue
        tmp = gcd(i, j)
        if tmp == 1:
            ans += N
            continue
        for k in range(1, N + 1):
            if k == 1:
                ans += 1
                continue
            ans += gcd(tmp, k)
print(ans)

import sys

sys.setrecursionlimit(10**9)
input = sys.stdin.readline
from itertools import permutations, combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop
from math import gcd

INF = float("inf")
NIL = -1
K = int(eval(input()))
total = 0
for a in range(1, K + 1):
    for b in range(1, K + 1):
        tmp = gcd(a, b)
        for c in range(1, K + 1):
            total += gcd(tmp, c)
print(total)

+sys.setrecursionlimit(10**9) -from itertools import * +from itertools import permutations, combinations, accumulate -from collections import * +from collections import deque, defaultdict, Counter - -# from math import gcd -def gcd(a, b): -    """ -    Greatest Common Divisor -    Euclidean Algortihm -    """ -    if a < b: -        gcd(b, a) -    while b != 0: -        a, b = b, a % b -    return a - +from math import gcd -N = int(eval(input())) -ans = 0 -for i in range(1, N + 1): -    if i == 1: -        ans += N**2 -        continue -    for j in range(1, N + 1): -        if j == 1: -            ans += N -            continue -        tmp = gcd(i, j) -        if tmp == 1: -            ans += N -            continue -        for k in range(1, N + 1): -            if k == 1: -                ans += 1 -                continue -            ans += gcd(tmp, k) -print(ans) +K = int(eval(input())) +total = 0 +for a in range(1, K + 1): +    for b in range(1, K + 1): +        tmp = gcd(a, b) +        for c in range(1, K + 1): +            total += gcd(tmp, c) +print(total)