import math

k = int(eval(input()))

sum = 0

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

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

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

            sum+=math.gcd(math.gcd(i,j),l)

print(sum)
k = int(eval(input()))

arr =  [0]*(k+1)

count = [0]*(k+1)

sum = 0

n = 3

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

    x = k//i

    p = int(pow(x,n))

    arr[i]=i*p 

    count[i]=p

    for j in range(x-1):

        arr[i]-=i*count[i*(j+2)]

        count[i]-=count[i*(j+2)]

csum = 0

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

    sum+=arr[i]

    csum+=count[i]

sum+=(int(pow(k,n)) - csum)

print((int(sum%(1e9+7))))



import math

k = int(eval(input()))
sum = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        for l in range(1, k + 1):
            sum += math.gcd(math.gcd(i, j), l)
print(sum)

k = int(eval(input()))
arr = [0] * (k + 1)
count = [0] * (k + 1)
sum = 0
n = 3
for i in range(k, 1, -1):
    x = k // i
    p = int(pow(x, n))
    arr[i] = i * p
    count[i] = p
    for j in range(x - 1):
        arr[i] -= i * count[i * (j + 2)]
        count[i] -= count[i * (j + 2)]
csum = 0
for i in range(2, k + 1):
    sum += arr[i]
    csum += count[i]
sum += int(pow(k, n)) - csum
print((int(sum % (1e9 + 7))))

-import math - +arr = [0] * (k + 1) +count = [0] * (k + 1) -for i in range(1, k + 1): -    for j in range(1, k + 1): -        for l in range(1, k + 1): -            sum += math.gcd(math.gcd(i, j), l) -print(sum) +n = 3 +for i in range(k, 1, -1): +    x = k // i +    p = int(pow(x, n)) +    arr[i] = i * p +    count[i] = p +    for j in range(x - 1): +        arr[i] -= i * count[i * (j + 2)] +        count[i] -= count[i * (j + 2)] +csum = 0 +for i in range(2, k + 1): +    sum += arr[i] +    csum += count[i] +sum += int(pow(k, n)) - csum +print((int(sum % (1e9 + 7))))