from functools import reduce 

import math

import itertools



def gcd(numbers):

    return reduce(lambda x,y: math.gcd(x,y),numbers)



def comb(K):

    return itertools.combinations_with_replacement(list(range(1,K+1)),3)



def main():

    k = int(eval(input()))

    if k == 1:

        print((1))

        return

    elif k == 2:

        print((9))

        return



    final = 0

    comb_list = list(comb(k))



    for i in comb_list:

        if len(set(i)) == 1:

            final += 1*gcd(i)

        elif len(set(i)) == 2:

            final += 3*gcd(i)

        else:

            final += math.factorial(3)*gcd(i)



    #print(comb_list)

    print(final)

main()

import math



def main():



    k = int(eval(input()))

    

    r = list(range(1,k+1))



    #because gcd can only appear in this range

    count = [0]*201

    

    for i in r:

        for j in r:

            count[math.gcd(i,j)] += 1

    

    final = 0

    

    for i in range(1,201):

        if count[i] > 0:

            for j in r:

                final += count[i]*math.gcd(i,j)

    

    print(final)





main()

from functools import reduce
import math
import itertools


def gcd(numbers):
    return reduce(lambda x, y: math.gcd(x, y), numbers)


def comb(K):
    return itertools.combinations_with_replacement(list(range(1, K + 1)), 3)


def main():
    k = int(eval(input()))
    if k == 1:
        print((1))
        return
    elif k == 2:
        print((9))
        return
    final = 0
    comb_list = list(comb(k))
    for i in comb_list:
        if len(set(i)) == 1:
            final += 1 * gcd(i)
        elif len(set(i)) == 2:
            final += 3 * gcd(i)
        else:
            final += math.factorial(3) * gcd(i)
    # print(comb_list)
    print(final)


main()

import math


def main():
    k = int(eval(input()))
    r = list(range(1, k + 1))
    # because gcd can only appear in this range
    count = [0] * 201
    for i in r:
        for j in r:
            count[math.gcd(i, j)] += 1
    final = 0
    for i in range(1, 201):
        if count[i] > 0:
            for j in r:
                final += count[i] * math.gcd(i, j)
    print(final)


main()

-from functools import reduce -import itertools - - -def gcd(numbers): -    return reduce(lambda x, y: math.gcd(x, y), numbers) - - -def comb(K): -    return itertools.combinations_with_replacement(list(range(1, K + 1)), 3) -    if k == 1: -        print((1)) -        return -    elif k == 2: -        print((9)) -        return +    r = list(range(1, k + 1)) +    # because gcd can only appear in this range +    count = [0] * 201 +    for i in r: +        for j in r: +            count[math.gcd(i, j)] += 1 -    comb_list = list(comb(k)) -    for i in comb_list: -        if len(set(i)) == 1: -            final += 1 * gcd(i) -        elif len(set(i)) == 2: -            final += 3 * gcd(i) -        else: -            final += math.factorial(3) * gcd(i) -    # print(comb_list) +    for i in range(1, 201): +        if count[i] > 0: +            for j in r: +                final += count[i] * math.gcd(i, j)