import math
from functools import reduce

def gcd(nums):
    return reduce(math.gcd, nums)

K = int(input())

a = []
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            a.append([i,j,k])

ans = 0
for i in a:
    ans += gcd(i)

print(ans)