Threes
View as PDFYou are given a positive integer, . Determine the minimum number of digits of 
 which must be replaced with 
's to make 
 divisible by 
.
Constraints
Input Specification
The first line contains one integer, .
Output Specification
Output one line containing one integer, the minimum number of digits of  which must be replaced with 
's to make 
 divisible by 
. It can be shown that it is always possible to make 
 divisible by 
.
Sample Input 1
31415
Sample Output 1
1
Explanation for Sample 1
If you replace the last digit of  with a 
, you get 
, which is divisible by 
. (
)
It can be shown that this is the minimal number of digit replacements.
Sample Input 2
42
Sample Output 2
0
Explanation for Sample 2
 is already divisible by 
, so no digit replacements are required.
Comments