from math import gcd

k=int(eval(input()))

cnt=0

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

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

    a=gcd(i,j)

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

      cnt+=gcd(a,k)

print(cnt)

k=int(eval(input()))

n=3

mod=10**9+7

lst=[0]*(k+1)

ans=0



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

  lst[i]+=pow(k//i,n,mod)

  if k//i==1:

    continue

  else:

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

      lst[i]-=lst[i*j]

      

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

  ans+=(i*lst[i])%mod

  ans%=mod

  

print(ans)
from math import gcd

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

k = int(eval(input()))
n = 3
mod = 10**9 + 7
lst = [0] * (k + 1)
ans = 0
for i in range(k, 0, -1):
    lst[i] += pow(k // i, n, mod)
    if k // i == 1:
        continue
    else:
        for j in range(2, k // i + 1):
            lst[i] -= lst[i * j]
for i in range(1, k + 1):
    ans += (i * lst[i]) % mod
    ans %= mod
print(ans)

-from math import gcd - -cnt = 0 +n = 3 +mod = 10**9 + 7 +lst = [0] * (k + 1) +ans = 0 +for i in range(k, 0, -1): +    lst[i] += pow(k // i, n, mod) +    if k // i == 1: +        continue +    else: +        for j in range(2, k // i + 1): +            lst[i] -= lst[i * j] -    for j in range(1, k + 1): -        a = gcd(i, j) -        for k in range(1, k + 1): -            cnt += gcd(a, k) -print(cnt) +    ans += (i * lst[i]) % mod +    ans %= mod +print(ans)