# import sys

# sys.setrecursionlimit(10 ** 6)

int1 = lambda x: int(x) - 1

def II(): return int(eval(input()))



def MI(): return list(map(int, input().split()))

def MI1(): return list(map(int1, input().split()))



def LI(): return list(map(int, input().split()))

def LLI(rows_number): return [LI() for _ in range(rows_number)]



import math



def solve():

    k = II()

    ans = 0

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

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

            g1 = math.gcd(a, b)

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

                g2 = math.gcd(g1, c)

                ans = ans + g2



    print(ans)



if __name__ == '__main__':

    solve()

import sys

sys.setrecursionlimit(10 ** 6)

# input = sys.stdin.readline    ####

int1 = lambda x: int(x) - 1

def II(): return int(eval(input()))



def MI(): return list(map(int, input().split()))

def MI1(): return list(map(int1, input().split()))



def LI(): return list(map(int, input().split()))

def LI1(): return list(map(int1, input().split()))

def LLI(rows_number): return [LI() for _ in range(rows_number)]



INF = float('inf')

#from fractions import gcd

from math import gcd



def solve():

    k = II() + 1

    ans = 0

    for a in range(1, k):

        for b in range(1, k):

            g = gcd(a, b)

            for c in range(1, k):

                ans += gcd(g, c)

    print(ans)





if __name__ == '__main__':

    solve()

# import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1


def II():
    return int(eval(input()))


def MI():
    return list(map(int, input().split()))


def MI1():
    return list(map(int1, input().split()))


def LI():
    return list(map(int, input().split()))


def LLI(rows_number):
    return [LI() for _ in range(rows_number)]


import math


def solve():
    k = II()
    ans = 0
    for a in range(1, k + 1):
        for b in range(1, k + 1):
            g1 = math.gcd(a, b)
            for c in range(1, k + 1):
                g2 = math.gcd(g1, c)
                ans = ans + g2
    print(ans)


if __name__ == "__main__":
    solve()

import sys

sys.setrecursionlimit(10**6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1


def II():
    return int(eval(input()))


def MI():
    return list(map(int, input().split()))


def MI1():
    return list(map(int1, input().split()))


def LI():
    return list(map(int, input().split()))


def LI1():
    return list(map(int1, input().split()))


def LLI(rows_number):
    return [LI() for _ in range(rows_number)]


INF = float("inf")
# from fractions import gcd
from math import gcd


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


if __name__ == "__main__":
    solve()

-# import sys -# sys.setrecursionlimit(10 ** 6) +import sys + +sys.setrecursionlimit(10**6) +# input = sys.stdin.readline    #### +def LI1(): +    return list(map(int1, input().split())) + + -import math +INF = float("inf") +# from fractions import gcd +from math import gcd -    k = II() +    k = II() + 1 -    for a in range(1, k + 1): -        for b in range(1, k + 1): -            g1 = math.gcd(a, b) -            for c in range(1, k + 1): -                g2 = math.gcd(g1, c) -                ans = ans + g2 +    for a in range(1, k): +        for b in range(1, k): +            g = gcd(a, b) +            for c in range(1, k): +                ans += gcd(g, c)