getGcd :: Int -> Int -> Int
getGcd a 0 = a
getGcd a b
    | a `mod` b == 0 = b
    | otherwise = getGcd b $ a `mod` b
    
main = do
    k <- read <$> getLine
    print $ sum [ getGcd c (getGcd a b) | a <- [1..k], b <- [1..k], c <- [1..k] ]