import Control.Monad
import Control.Applicative
import Data.List
import Data.Array
import Data.Array.IO
import Data.Maybe
import Data.Bits
import Data.Ord
import qualified Data.ByteString.Char8 as BS
import qualified Data.Set as Set
import Debug.Trace
import Numeric

modifyArray arr i f = readArray arr i >>= \x -> writeArray arr i (f x)

listToTuple2 [a,b] = (a,b)
listToTuple3 [a,b,c] = (a,b,c)
listToTuple4 [a,b,c,d] = (a,b,c,d)

getWords = getLine >>= return . words

readIntBS = fst . fromJust . BS.readInt


main :: IO ()
main = do
  n <- readLn :: IO Int
  as <- newListArray (1,n) =<< map read . words <$> getLine :: IO (IOArray Int Int)

  replicateM_ n $ do
    xs <- f <$> freeze as
    let b = fmap (n-) $ findIndex (<0) (reverse xs)
    when (isJust b) $ do
      let Just i = b
      forM_ (takeWhile (<=n) $ iterate (+i) i) $ \x -> do
        writeArray as x 0

  print =<< sum <$> getElems as
  
  where
    f a = [sum $ map (\x -> a!x) (takeWhile (<=u) $ iterate (+i) i) | i<-[l..u]]
      where
        (l,u) = bounds a
