{-# LANGUAGE Strict #-}

main :: IO ()
main = do
  k <- readLn
  print $ solve k

solve :: Int -> Int
solve k = sum [gcd3 a b c | a <- [1 .. k], b <- [1 .. k], c <- [1 .. k]]

gcd3 :: Int -> Int -> Int -> Int
gcd3 a b c = gcd (gcd a b) c
