from math import*;from itertools import*;r=list(range(1,int(eval(input()))+1));print((sum(gcd(a,gcd(b,c))for a,b,c in product(r,r,r))))
from math import*;r=list(range(1,int(eval(input()))+1));print((sum(gcd(a,gcd(b,c))for a in r for b in r for c in r)))
from math import *
from itertools import *

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

from math import *

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

-from itertools import * -print((sum(gcd(a, gcd(b, c)) for a, b, c in product(r, r, r)))) +print((sum(gcd(a, gcd(b, c)) for a in r for b in r for c in r)))