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



Ans=0

from math import gcd

for i in range(1,K):

    for j in range(1,K):

        tempA=gcd(i,j)

        for k in range(K-1):

            Ans+=gcd(tempA,k+1)

            

print(Ans)

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



Ans=0

from math import gcd

for i in range(K-1):

    for j in range(K-1):

        tempA=gcd(i+1,j+1)

        for k in range(1,K):

            Ans+=gcd(tempA,k)

            

print(Ans)

K = int(eval(input())) + 1
Ans = 0
from math import gcd

for i in range(1, K):
    for j in range(1, K):
        tempA = gcd(i, j)
        for k in range(K - 1):
            Ans += gcd(tempA, k + 1)
print(Ans)

K = int(eval(input())) + 1
Ans = 0
from math import gcd

for i in range(K - 1):
    for j in range(K - 1):
        tempA = gcd(i + 1, j + 1)
        for k in range(1, K):
            Ans += gcd(tempA, k)
print(Ans)

-for i in range(1, K): -    for j in range(1, K): -        tempA = gcd(i, j) -        for k in range(K - 1): -            Ans += gcd(tempA, k + 1) +for i in range(K - 1): +    for j in range(K - 1): +        tempA = gcd(i + 1, j + 1) +        for k in range(1, K): +            Ans += gcd(tempA, k)