import sys
import numpy as np
import math
# for AtCoder
import fractions
from collections import deque 
from functools import reduce

# input = sys.stdin.readline

n = int(input())

sum = 0

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

for i in range(1, n+1):
    for j in range(1, n+1):
        for k in range(1, n+1):
            sum += gcd_list([i, j, k])
print(sum)
