TWOVSTEN - Editorial

PROBLEM LINK:

Practice
Contest

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 :

  1. If the number is already divisible by 10, then the answer is 0.

  2. If the number is divisible by 5, then the answer is 1. It can be proved,
    Consider N = K * 5, then if we apply the operation once, it becomes, N = K * 5 * 2 which in turn simpllifies to N = K * 10, thus giving the desired result.

  3. 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 by 5 and 2.

Author’s code

AUTHOR’S AND TESTER’S SOLUTIONS:

Author’s solution can be found here.
Tester’s solution can be found here.