ret_sub :: Integer -> Integer -> Integer -> Integer -> Integer
ret_sub num id n k =
    if (id > n) then
        num
    else
        if (mod (((mod (-id) k) + k)*2) k == 0) then
            let a = div n k + if (mod n k >= mod (-id) k && mod (-id) k /= 0) then 1 else 0 in
            ret_sub (num + a*a) (id + 1) n k
        else
            ret_sub num (id + 1) n k


ret :: Integer -> Integer -> Integer
ret n k = ret_sub 0 1 n k


main = do
    hoge <- getLine
    let [n, k] = map read $ words hoge
    putStrLn $ show $ ret n k