PROBLEM LINK:
Author: Denis Anishchenko
Tester: Hasan Jaddouh
Editorialist: Sarv Shakti Singh
Difficulty: cakewalk
Prerequisites: Basic math
Problem: Given a number X
, the operation allowed is multiplication by 2, find the minimum number of times the operation has to be performed to make X
divisible by 10.
Explanation: The approach is quite simple and can be classified in 3 cases :
-
If the number is already divisible by 10, then the answer is 0.
-
If the number is divisible by 5, then the answer is 1. It can be proved,
ConsiderN = K * 5
, then if we apply the operation once, it becomes,N = K * 5 * 2
which in turn simpllifies toN = K * 10
, thus giving the desired result. -
If the number doesn’t fall in previous 2 cases, then it is impossible to achieve the desired result, as for a number to be divisible by
10
, it has to be divisble by5
and2
.
AUTHOR’S AND TESTER’S SOLUTIONS:
Author’s solution can be found here.
Tester’s solution can be found here.