import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import qualified Data.Vector as V

main = abc162c

abc162c = do
    [k] <- getIntList
    print $ sum (gcd3List $ fromIntegral k)

getGCD (a, b)
    | a < b = getGCD (b, a)
    | mod a b == 0 = b
    | otherwise = getGCD (b, mod a b)

getGCD3 (a, b, c) = getGCD (getGCD (a,b), getGCD (a,c)) 

gcd3List k = [getGCD3 (a,b,c) | a <- [1..k], b <- [1..k], c <- [1..k]]

readInt = fst . fromJust . BS.readInteger
readIntList = map readInt . BS.words
getIntList = readIntList <$> BS.getLine