import numpy as np

from itertools import combinations



def main():

    k = int(eval(input()))

    res = 0

    memo = np.zeros((k+1, k+1), int)

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

        for j in range(i, k+1):

            tmp = np.gcd(i,j)

            memo[i][j] = tmp

            memo[j][i] = tmp



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

        res += i 



    for c in combinations(list(range(1,k+1)),2):

        ab = memo[c[0], c[1]]

        res += ab * 6



    for c in combinations(list(range(1,k+1)), 3):

        ab = memo[c[0], c[1]]

        abc = memo[ab, c[2]]

        res += abc * 6

    print(res)





if __name__ == '__main__':

    main()



import math

from itertools import combinations



def main():

    k = int(eval(input()))

    res = 0

    memo = [[0 for _ in range(k+1)] for _ in range(k+1)]

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

        for j in range(i, k+1):

            tmp = math.gcd(i,j)

            memo[i][j] = tmp

            memo[j][i] = tmp



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

        res += i 



    for c in combinations(list(range(1,k+1)),2):

        ab = memo[c[0]][c[1]]

        res += ab * 6



    for c in combinations(list(range(1,k+1)), 3):

        ab = memo[c[0]][c[1]]

        abc = memo[ab][c[2]]

        res += abc * 6

    print(res)





if __name__ == '__main__':

    main()



import numpy as np
from itertools import combinations


def main():
    k = int(eval(input()))
    res = 0
    memo = np.zeros((k + 1, k + 1), int)
    for i in range(1, k + 1):
        for j in range(i, k + 1):
            tmp = np.gcd(i, j)
            memo[i][j] = tmp
            memo[j][i] = tmp
    for i in range(1, k + 1):
        res += i
    for c in combinations(list(range(1, k + 1)), 2):
        ab = memo[c[0], c[1]]
        res += ab * 6
    for c in combinations(list(range(1, k + 1)), 3):
        ab = memo[c[0], c[1]]
        abc = memo[ab, c[2]]
        res += abc * 6
    print(res)


if __name__ == "__main__":
    main()

import math
from itertools import combinations


def main():
    k = int(eval(input()))
    res = 0
    memo = [[0 for _ in range(k + 1)] for _ in range(k + 1)]
    for i in range(1, k + 1):
        for j in range(i, k + 1):
            tmp = math.gcd(i, j)
            memo[i][j] = tmp
            memo[j][i] = tmp
    for i in range(1, k + 1):
        res += i
    for c in combinations(list(range(1, k + 1)), 2):
        ab = memo[c[0]][c[1]]
        res += ab * 6
    for c in combinations(list(range(1, k + 1)), 3):
        ab = memo[c[0]][c[1]]
        abc = memo[ab][c[2]]
        res += abc * 6
    print(res)


if __name__ == "__main__":
    main()

-import numpy as np +import math -    memo = np.zeros((k + 1, k + 1), int) +    memo = [[0 for _ in range(k + 1)] for _ in range(k + 1)] -            tmp = np.gcd(i, j) +            tmp = math.gcd(i, j) -        ab = memo[c[0], c[1]] +        ab = memo[c[0]][c[1]] -        ab = memo[c[0], c[1]] -        abc = memo[ab, c[2]] +        ab = memo[c[0]][c[1]] +        abc = memo[ab][c[2]]