lst k = [(x, y, z) | x <- [1..k], y <- [1..k], z <- [1..k]]

solve :: [(Int, Int, Int)] -> [Int]
solve [] = []
solve ((x, y, z) : xs) = [gcd x (gcd y z)] ++ solve xs

main = do
    k <- readLn :: IO Int
    print $ sum (solve (lst k))
