import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
getInt = readInt <$> BS.getLine

main = do
    k <- getInt
    let s1 = sum [gcd (gcd a b) c | a <- [1..k-2], b <- [a+1..k-1], c <- [b+1..k]]
        s2 = sum [gcd a b | a <- [1..k-1], b <- [a+1..k]]
        s3 = sum [1..k]
    print $ (6 * s1) + (6 * s2) + s3