main = map read . words <$> getLine >>= \[n, k] -> print (patterns n k)
patterns n k  
  | even k    =   6 * length  [() | 
                              a <- [k `div` 2, k .. n], 
                              b <- [a + k `div` 2, a + k .. n], 
                              c <- [b + k `div` 2, b + k .. n],
                              (a + b) `mod` k == 0,
                              (b + c) `mod` k == 0,
                              (c + a) `mod` k == 0] +
                  6 * length  [() |
                              ab <- [k `div` 2, k .. n],
                              c  <- [ab + k `div` 2, ab + k .. n],
                              (ab + ab) `mod` k == 0,
                              (ab + c) `mod` k == 0] +
                  length      [() |
                              abc <- [k `div` 2, k .. n],
                              (abc + abc) `mod` k == 0]
  | otherwise =   6 * length  [() | 
                              a <- [k, k + k .. n], 
                              b <- [a + k, a + k + k .. n], 
                              c <- [b + k, b + k + k .. n],
                              (a + b) `mod` k == 0,
                              (b + c) `mod` k == 0,
                              (c + a) `mod` k == 0] +
                  6 * length  [() |
                              ab <- [k, k + k .. n],
                              c  <- [ab + k, ab + k + k .. n],
                              (ab + ab) `mod` k == 0,
                              (ab + c) `mod` k == 0] +
                  length      [() |
                              abc <- [k, k + k .. n],
                              (abc + abc) `mod` k == 0]