module Main where
import qualified Control.Monad as C
import qualified Data.Char as C
import qualified Data.List as L
import qualified Data.Map as M
import qualified Data.Array as A

int = read :: String -> Int
long = read :: String -> Integer
getWord :: IO String
getWord = do
  c <- getChar
  if C.isSpace c
  then
    return []
  else do
    ws <- getWord
    return (c:ws)
getInt = fmap int getWord
replace pred a = map (\x -> if pred x then a else x)

main = interact $ printer . solver . parser
parser = long . head . words
printer = unlines . (:[]) . show

gcd3 a b c = gcd a $ gcd b c

solver k = sum [(if a==b && b==c then 1 else if a/=b && b/=c then 6 else 3) * gcd3 a b c | a<-[1..k], b<-[a..k], c<-[b..k]]