import Data.List
import Data.Array

main = readLn >>= print.sum.gcds

gcds :: Int -> [Int]
gcds n = map (gcd3.calcK) [ [x,y,z] | x <- [1..n], y <- [1..x], z <- [1..y]]
calcK [x,y,z] = a : [x,y,z] where
  a = if x == y && y == z then 1
    else if x == y || y == z then 3 else 6
gcd3 [a,x,y,z] = a * gcd(gcd x y) z