Given a number N, the task is to check whether the number is divisible by 43 or not.
Input: N = 2795
43 * 65 = 2795
Input: N = 11094
43 * 258 = 11094
Approach: The divisibility test of 43 is:
- Extract the last digit.
- Add 13 * 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 43, or it is 0, then the original number is also divisible by 43.
If N = 11739 Step 1: N = 11739 Last digit = 9 Remaining number = 1173 Adding 13 times last digit Resultant number = 1173 + 13*9 = 1290 Step 2: N = 1290 Since 129 is divisible by 43 as 43 * 3 = 129 Therefore N = 11739 is also divisible by 43
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.