main = interact $ unlines . map (show . factorial2 . read) . (takeWhile (/="0")) . lines
factorial2 n = zeros + comps_of_zero + unknown
 where
  zeros = sum $ takeWhile (/=0) $ map (div n) $ iterate (*10) 10
  comps_of_zero = sum $ takeWhile (/=0) $ map (\z -> num_of_composite z * div n z) $ iterate (*10) 10
  unknown = sum $ take (length (show n) - 2) $ iterate (*2) 1
  num_of_composite n = length $ filter (\n' -> n/=n'^2 && mod n n' == 0) [2..(floor $ sqrt $ fromIntegral n)]