codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

102B.md (1337B)


      1 Source: https://codeforces.com/problemset/problem/102/B
      2 
      3 B. Sum of Digits
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 265 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-digit?
     22 
     23 Input
     24 
     25 The first line contains the only integer *n* (0 ≤ *n* ≤ 10100000). It is guaranteed that *n* doesn't contain any leading zeroes.
     26 
     27 Output
     28 
     29 Print the number of times a number can be replaced by the sum of its digits until it only contains one digit.
     30 
     31 Examples
     32 
     33 Input
     34 
     35 ```
     36 0
     37 ```
     38 
     39 Output
     40 
     41 ```
     42 0
     43 ```
     44 
     45 Input
     46 
     47 ```
     48 10
     49 ```
     50 
     51 Output
     52 
     53 ```
     54 1
     55 ```
     56 
     57 Input
     58 
     59 ```
     60 991
     61 ```
     62 
     63 Output
     64 
     65 ```
     66 3
     67 ```
     68 
     69 Note
     70 
     71 In the first sample the number already is one-digit — Herald can't cast a spell.
     72 
     73 The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.
     74 
     75 The third test contains number 991. As one casts a spell the following transformations take place: 991 → 19 → 10 → 1. After three transformations the number becomes one-digit.