readInt :: String -> Int
readInt = read

main = do
    s <- map readInt.words<$>getLine
    print $ solve s

solve :: [Int] -> Int
solve [n, k] = length [(a,b,c)| a <- [1..n], b <- [1..n], c <- [1..n], check a b c]
 where
  check a b c = (q a b)&&(q b c)&&(q c a)
   where
    q x y = (mod (x+y) k == 0)