import math

num = (int)(eval(input()))

total = 0

 

for i in range(1, num + 1):

  for j in range(1, num + 1):

    sub = math.gcd(i, j)

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

      total += math.gcd(sub, k)

print(total)
from math import gcd

num = (int)(eval(input()))

total = 0

 

for i in range(1, num + 1):

  for j in range(1, num + 1):

    sub = gcd(i, j)

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

      total += gcd(sub, k)

print(total)

import math

num = (int)(eval(input()))
total = 0
for i in range(1, num + 1):
    for j in range(1, num + 1):
        sub = math.gcd(i, j)
        for k in range(1, num + 1):
            total += math.gcd(sub, k)
print(total)

from math import gcd

num = (int)(eval(input()))
total = 0
for i in range(1, num + 1):
    for j in range(1, num + 1):
        sub = gcd(i, j)
        for k in range(1, num + 1):
            total += gcd(sub, k)
print(total)

-import math +from math import gcd -        sub = math.gcd(i, j) +        sub = gcd(i, j) -            total += math.gcd(sub, k) +            total += gcd(sub, k)