import Control.Arrow
import Data.List
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = breads >>= print . solve 

-- | 
-- >>> solve [3,2]
-- 9
-- >>> solve [5, 3]
-- 1
-- >>> solve [31415,9265]
-- 27
-- >>> solve [35897,932]
-- 114191
solve :: [Int] -> Int 
solve [n, k]
    | odd k = zn ^ 3
    | otherwise = zn ^ 3 + hn ^ 3
    where
        zn = foldl' ff1 0 [1..n]
        hn = foldl' ff2 0 [1..n]

        ff1 acc x 
            | x `mod` k == 0 = acc + 1
            | otherwise = acc
        ff2 acc x 
            | x `mod` k == hk = acc + 1
            | otherwise = acc
        
        hk = k `div` 2

breads :: IO [Int]
breads = unfoldr (\s -> second (maybe B.empty snd . B.uncons) <$> B.readInt s) <$> B.getLine