# -*- coding: utf-8 -*-
import math
k = int(input())
#a = [int(i) for i in input().split()]

ans = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        tmp = math.gcd(i, j)
        for k in range(1, k + 1):
            #tmp = math.gcd(i, j)
            tmp2 = math.gcd(tmp, k)
            ans += tmp2
print(ans)
