toInt :: String -> Int
toInt = read :: String -> Int

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

main = do
  n <- toInt <$> getLine
  print $ sum [gcd3 a b c | a <- [1..n], b <- [1..n], c <- [1..n]]
