from fractions import gcd

 

def main():

  k = int(eval(input()))

  ans = 0

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

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

      x = gcd(a,b)

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

        if a==b and b==c:

          ans += a

        elif a==b or b==c:

          ans += gcd(x,c) * 3

        else:

          ans += gcd(x,c) * 6

  print(ans)

  

  

if __name__ == '__main__':

  main()
from math import gcd

 

def main():

  k = int(eval(input()))

  ans = 0

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

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

      x = gcd(a,b)

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

        if a==b and b==c:

          ans += a

        elif a==b or b==c:

          ans += gcd(x,c) * 3

        else:

          ans += gcd(x,c) * 6

  print(ans)

  

  

if __name__ == '__main__':

  main()

from fractions import gcd


def main():
    k = int(eval(input()))
    ans = 0
    for a in range(1, k + 1):
        for b in range(a, k + 1):
            x = gcd(a, b)
            for c in range(b, k + 1):
                if a == b and b == c:
                    ans += a
                elif a == b or b == c:
                    ans += gcd(x, c) * 3
                else:
                    ans += gcd(x, c) * 6
    print(ans)


if __name__ == "__main__":
    main()

from math import gcd


def main():
    k = int(eval(input()))
    ans = 0
    for a in range(1, k + 1):
        for b in range(a, k + 1):
            x = gcd(a, b)
            for c in range(b, k + 1):
                if a == b and b == c:
                    ans += a
                elif a == b or b == c:
                    ans += gcd(x, c) * 3
                else:
                    ans += gcd(x, c) * 6
    print(ans)


if __name__ == "__main__":
    main()

-from fractions import gcd +from math import gcd