gcd3 :: Integral a => a -> a -> a -> a
gcd3 a b c = gcd a $ gcd b c


compute :: Integral a => a -> a
compute k = sum [gcd3 a b c | a <- [1 .. k], b <- [1 .. k], c <- [1 .. k]]


main :: IO ()
main = do
    k <- readLn :: IO Int
    print $ compute k