Given a number N, the task is to check whether the number is divisible by 71 or not.
Input: N = 25411681
71 * 357911 = 25411681
Input: N = 5041
71 * 71 = 5041
Approach: The divisibility test of 71 is:
- Extract the last digit.
- Subtract 7 * last digit from the remaining number obtained after removing the last digit.
- Repeat the above steps until a two-digit number, or zero, is obtained.
- If the two-digit number is divisible by 71, or it is 0, then the original number is also divisible by 71.
If N = 5041 Step 1: N = 5041 Last digit = 1 Remaining number = 504 Subtracting 7 times last digit Resultant number = 504 - 7*1 = 497 Step 2: N = 497 Last digit = 7 Remaining number = 49 Subtracting 7 times last digit Resultant number = 49 - 7*7 = 0 Step 3: N = 0 Since N is a two-digit number, and 0 is divisible by 71 Therefore N = 5041 is also divisible by 71
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important mathematical concepts for competitive programming with the Essential Maths for CP Course at a student-friendly price. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.