(<&>) = flip fmap

count :: (a -> Bool) -> [a] -> Int
count f (x:[]) = if f x then 1 else 0
count f (x:xs) = (if f x then 1 else 0) + (count f xs)

main = do
    [n, k] <- map read . words <$> getLine
    let modEqualList = [0] ++ (if (even k) then [quot k 2] else [])
    let combinations = modEqualList <&> (\e -> count (\m -> mod m k == e) [1..n]) <&> (flip (^) 3)
    putStrLn $ show $ sum combinations
