def c_sum_of_gcd_of_tuples_easy():

    from math import gcd

    K = int(eval(input()))



    ans = 0

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

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

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

                ans += gcd(gcd(a, b), c)

    return ans



print((c_sum_of_gcd_of_tuples_easy()))
def c_sum_of_gcd_of_tuples_easy():

    import numpy as np

    K = int(eval(input()))



    r = np.arange(1, K + 1)

    return np.gcd.outer(np.gcd.outer(r, r), r).sum()



print((c_sum_of_gcd_of_tuples_easy()))
def c_sum_of_gcd_of_tuples_easy():
    from math import gcd

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


print((c_sum_of_gcd_of_tuples_easy()))

def c_sum_of_gcd_of_tuples_easy():
    import numpy as np

    K = int(eval(input()))
    r = np.arange(1, K + 1)
    return np.gcd.outer(np.gcd.outer(r, r), r).sum()


print((c_sum_of_gcd_of_tuples_easy()))

-    from math import gcd +    import numpy as np -    ans = 0 -    for a in range(1, K + 1): -        for b in range(1, K + 1): -            for c in range(1, K + 1): -                ans += gcd(gcd(a, b), c) -    return ans +    r = np.arange(1, K + 1) +    return np.gcd.outer(np.gcd.outer(r, r), r).sum()