from math import gcd

k=int(eval(input()))+1

print((sum(gcd(c,gcd(a,b))for a in range(1,k)for b in range(1,k)for c in range(1,k))))
from numpy import*;f=gcd.outer;r=list(range(1,int(eval(input()))+1));print((sum(f(f(r,r),r))))
from math import gcd

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

from numpy import *

f = gcd.outer
r = list(range(1, int(eval(input())) + 1))
print((sum(f(f(r, r), r))))

-from math import gcd +from numpy import * -k = int(eval(input())) + 1 -print( -    ( -        sum( -            gcd(c, gcd(a, b)) -            for a in range(1, k) -            for b in range(1, k) -            for c in range(1, k) -        ) -    ) -) +f = gcd.outer +r = list(range(1, int(eval(input())) + 1)) +print((sum(f(f(r, r), r))))