import Data.Maybe
import Control.Monad
import qualified Data.ByteString.Char8 as C

readInteger = fst.fromJust.C.readInteger
readLnInteger = map readInteger.C.words<$>C.getLine
readCsInteger n = concat<$>replicateM n readLnInteger

x ? (a,b) = if x then a else b
a~>(f,x) = [a] ++ (null x)?([],f x)
half = flip div 2
aliq = ((0==).).mod

main = do
  [n] <- readLnInteger
  print $ solve n

solve n = calc n [n,n,n] 0

calc n [0,0,0] t = t
calc n [a,b,c] t = calc n list t' where
  list = [mec [a,b,c] [a,a,a-1],mec [a,b,c] [b,b-1,n],mec [a,b,c] [c-1,n,n]]
  t' = t + (foldr1 gcd [a,b,c])

mec [a,b,c][d,e,f]
 | c/=1 = d
 | b/=1 = e
 | a/=1 = f
 | otherwise = 0
