from math import gcd

K=int(eval(input()))

a=0

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

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

        t=gcd(i,j)

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

            a+=gcd(t,k)

print(a)

K=int(eval(input()))

N=3

pr=10**9+7

a=0

l=[None]*(K+1)

for i in range(K,0,-1):

    t=pow(K//i,N,pr)

    c=i*2

    while c<=K:

        t-=l[c]

        c+=i

    l[i]=t

    a=(a+t*i)%pr

print(a)
from math import gcd

K = int(eval(input()))
a = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        t = gcd(i, j)
        for k in range(1, K + 1):
            a += gcd(t, k)
print(a)

K = int(eval(input()))
N = 3
pr = 10**9 + 7
a = 0
l = [None] * (K + 1)
for i in range(K, 0, -1):
    t = pow(K // i, N, pr)
    c = i * 2
    while c <= K:
        t -= l[c]
        c += i
    l[i] = t
    a = (a + t * i) % pr
print(a)

-from math import gcd - +N = 3 +pr = 10**9 + 7 -for i in range(1, K + 1): -    for j in range(1, K + 1): -        t = gcd(i, j) -        for k in range(1, K + 1): -            a += gcd(t, k) +l = [None] * (K + 1) +for i in range(K, 0, -1): +    t = pow(K // i, N, pr) +    c = i * 2 +    while c <= K: +        t -= l[c] +        c += i +    l[i] = t +    a = (a + t * i) % pr