Buggy python submission (verdict: Time Limit Exceeded):
from itertools import product
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    ans=0
    K=int(input())
    KK=[i for i in range(1,K+1)]
    from functools import reduce
    from math import gcd

    I=list(product(KK,repeat=3))
    for i in I:
        ans+=reduce(gcd,i)
    print(ans)


resolve()

Fixed submission:
from itertools import combinations_with_replacement
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    ans=0
    K=int(input())
    KK=[i for i in range(1,K+1)]
    from functools import reduce
    from math import gcd

    I=list(combinations_with_replacement(KK,3))
    for i in I:
        ls=len(set(i))
        if ls==1:
            ans+=reduce(gcd,i)
        elif ls == 2:
            ans+=reduce(gcd,i)*3
        else:
            ans+=reduce(gcd,i)*6





    print(ans)


resolve()

Buggy python submission (verdict: Runtime Error):
from itertools import product
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    ans=0
    K=int(input())
    KK=[i for i in range(1,K+1)]
    from functools import reduce
    from math import gcd

    I=list(product(KK,repeat=3))
    for i in I:
        ans+=reduce(gcd,S)
    print(ans)


resolve()


Fixed submission:
from itertools import combinations_with_replacement
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    ans=0
    K=int(input())
    KK=[i for i in range(1,K+1)]
    from functools import reduce
    from math import gcd

    I=list(combinations_with_replacement(KK,3))
    for i in I:
        ls=len(set(i))
        if ls==1:
            ans+=reduce(gcd,i)
        elif ls == 2:
            ans+=reduce(gcd,i)*3
        else:
            ans+=reduce(gcd,i)*6





    print(ans)


resolve()

Buggy python submission (verdict: Runtime Error):
from itertools import product
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    ans=0
    K=int(input())
    KK=[i for i in range(1,K+1)]
    from functools import reduce
    from math import gcd

    I=list(product(KK,repeat=3))
    for i in I:
        ans+=reduce(gcd,S)
    print(ans)


resolve()


Fixed submission:
from itertools import combinations_with_replacement
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    ans=0
    K=int(input())
    KK=[i for i in range(1,K+1)]
    from functools import reduce
    from math import gcd

    I=list(combinations_with_replacement(KK,3))
    for i in I:
        ls=len(set(i))
        if ls==1:
            ans+=reduce(gcd,i)
        elif ls == 2:
            ans+=reduce(gcd,i)*3
        else:
            ans+=reduce(gcd,i)*6





    print(ans)


resolve()

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    ans=0
    K=int(input())
    KK=[i for i in range(1,K+1)]
    from functools import reduce
    from math import gcd

    I=list(product(KK,repeat=3))
    for i in I:
        S=list(i)
        ans+=reduce(gcd,S)
    print(ans)


resolve()

Fixed submission:
from itertools import combinations_with_replacement
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    ans=0
    K=int(input())
    KK=[i for i in range(1,K+1)]
    from functools import reduce
    from math import gcd

    I=list(combinations_with_replacement(KK,3))
    for i in I:
        ls=len(set(i))
        if ls==1:
            ans+=reduce(gcd,i)
        elif ls == 2:
            ans+=reduce(gcd,i)*3
        else:
            ans+=reduce(gcd,i)*6





    print(ans)


resolve()