module Main where
import Data.Char
int = read :: String -> Int
inte = read :: String -> Integer
getWord :: IO String
getWord = do
  c <- getChar
  if isSpace c
  then
    return []
  else do
    ws <- getWord
    return (c:ws)
getInt = fmap int getWord
replace pred a = map (\x -> if pred x then a else x)

main = interact $ printer . solver . parser
parser = map inte . words
printer = unlines . (:[]) . show 

solver :: [Integer] -> Integer
solver [n,k] = sum $ map (takahashi n k) [1..n]

takahashi :: Integer -> Integer -> Integer -> Integer
takahashi n k b =
  if k <= b-1
  then (n `div` b) * (b - k) + max 0 ((n `mod` b) - (k-1))
  else 0
    

