import Control.Applicative import Control.Monad import Control.Monad.ST import Data.Array.ST import Data.STRef primes :: Int -> [Int] primes n = runST $ do a <- newArray (0, n) True :: ST s (STUArray s Int Bool) forM_ (takeWhile (\i -> i * i <= n) [3, 5..]) $ \i -> do v <- readArray a i when v $ forM_ [i * i, i * i + i .. n] $ \j -> writeArray a j False ps <- newSTRef [] :: ST s (STRef s [Int]) modifySTRef ps (2:) forM_ [3, 5..n] $ \i -> do v <- readArray a i when v $ modifySTRef ps (i:) readSTRef ps solve n l = sum . map f $ primes (10 ^ 7) where f p = max 0 (l - p * (n - 1) + 1) main = do [n, l] <- map read . words <$> getLine :: IO [Int] print $ solve n l