main = do
  li <- getLine
  let k = read li
  let ans = compute k
  print ans

{- naive -}

compute :: Int -> Int
compute k = sum
  [ gcd g c
  | a <- [1..k]
  , b <- [1..k]
  , let g = gcd a b
  , c <- [1..k]
  ]
