import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B
import Debug.Trace
main :: IO ()
main = readLine >>= print . solve

solve :: [Int] -> Int
solve [n, k]
    | odd k = kc ^ 3
    | otherwise = kc ^ 3 + khc ^ 3
    where
        kc = length $ filter (\x -> x `mod` k == 0) [1..n]
        khc = length $ filter (\x -> x `mod` k /= 0 && x `mod` (k `div` 2) == 0) [1..n]


readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine