type 'a church_list = { fold : 'b. ('a -> 'b -> 'b) -> 'b -> 'b }

let factorize :
  (* 素因数分解する整数 *)
  int ->
  (* 素因数と指数の組のリスト
     素因数について降順に出てくる *)
  (int * int) church_list
= fun n ->
  (* nをpで割れるだけ割って，割れた数c'にcを加えたものとn/p^c'を返す *)
  let rec iter_div p c n k =
    if 0 < n mod p
    then k c n
    else iter_div p (c + 1) (n / p) k in
  (* 素因数分解の処理の本体 *)
  let rec factorize f acc p n =
    if n <= 1
    then acc
    else if n < p * p
    then f (n, 1) acc
    else iter_div p 0 n @@ fun c ->
           factorize f (if c <= 0 then acc else f (p, c) acc) (p + 1) in
  { fold = fun f acc -> factorize f acc 2 n }

let rec upper_bound l r p =
  if r <= 1 + l
  then l
  else let m = (l + r) / 2 in
       if p m 
       then upper_bound m r p
       else upper_bound l m p

let rec f n x =
  if x - n < 0 then n - 1
  else f (n + 1) (x - n)
let f = f 1

let () = Scanf.scanf "%d" @@ fun n ->
  Printf.printf "%d\n" @@
  (factorize n).fold (fun (_, n) -> ( + ) @@ f n) 0

