{-# LANGUAGE StrictData #-}
main = do
    k <- readLn
    print $ 6*(sum [euclid a $ euclid b c | a <- [3..k], b <- [2..a-1], c <- [1..b-1]]) + 6*(sum [euclid a b | a <- [2..k], b <- [1..a-1]]) + (k*(k+1))`div`2

euclid :: Int -> Int -> Int
euclid a b = if b == 0 then a else euclid b (a`mod`b)