from math import*

r = list(range(1, int(eval(input())) + 1))

print((sum(gcd(gcd(a, b), c) for a in r for b in r for c in r)))
from math import gcd

r = list(range(1, int(eval(input())) + 1))

print((sum(gcd(gcd(a, b), c) for a in r for b in r for c in r)))
from math import *

r = list(range(1, int(eval(input())) + 1))
print((sum(gcd(gcd(a, b), c) for a in r for b in r for c in r)))

from math import gcd

r = list(range(1, int(eval(input())) + 1))
print((sum(gcd(gcd(a, b), c) for a in r for b in r for c in r)))

-from math import * +from math import gcd