{-# LANGUAGE PartialTypeSignatures #-}
{-# LANGUAGE StrictData #-}
module Main (main) where

import qualified Data.ByteString.Char8 as C8
import qualified Data.Char as C
import qualified Data.List as L
import Data.Maybe

main :: IO ()
main = readInts >>= output . solve

solve :: [Int] -> _
solve [n] = sum [f a b c | a <- [1..n], b <- [1..n], c <- [1..n]]
  where
    f 1 _ _ = 1
    f _ 1 _ = 1
    f _ _ 1 = 1
    f a b c = gcd (gcd a b) c

output :: _ -> IO ()
output = print

-- utils
readInts :: IO [Int]
readInts = L.unfoldr (C8.readInt . C8.dropWhile C.isSpace) <$> C8.getLine
