k = int(eval(input()))



sum = 0



def gcd(a, b):

    if b == 0:

        return a

    

    return gcd(b, a % b)





for a in range(1, k + 1):

    for b in range(1, k + 1):

        ab_gcd = gcd(a, b)

        for c in range(1, k + 1):

            abc_gcd = gcd(c, ab_gcd)

            sum += abc_gcd

        

print(sum)

import math



K = int(eval(input()))

ans = 0

for a in range(1, K+1):

    for b in range(1, K + 1):

        ab_gcd = math.gcd(a, b)

        for c in range(1, K + 1):

            ans += math.gcd(ab_gcd, c)

print(ans)

k = int(eval(input()))
sum = 0


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


for a in range(1, k + 1):
    for b in range(1, k + 1):
        ab_gcd = gcd(a, b)
        for c in range(1, k + 1):
            abc_gcd = gcd(c, ab_gcd)
            sum += abc_gcd
print(sum)

import math

K = int(eval(input()))
ans = 0
for a in range(1, K + 1):
    for b in range(1, K + 1):
        ab_gcd = math.gcd(a, b)
        for c in range(1, K + 1):
            ans += math.gcd(ab_gcd, c)
print(ans)

-k = int(eval(input())) -sum = 0 +import math - -def gcd(a, b): -    if b == 0: -        return a -    return gcd(b, a % b) - - -for a in range(1, k + 1): -    for b in range(1, k + 1): -        ab_gcd = gcd(a, b) -        for c in range(1, k + 1): -            abc_gcd = gcd(c, ab_gcd) -            sum += abc_gcd -print(sum) +K = int(eval(input())) +ans = 0 +for a in range(1, K + 1): +    for b in range(1, K + 1): +        ab_gcd = math.gcd(a, b) +        for c in range(1, K + 1): +            ans += math.gcd(ab_gcd, c) +print(ans)