Write an Efficient Method to Check if a Number is Multiple of 3 The very first solution that comes to our mind is the one that we learned in school. If sum of digits in a number is multiple of 3 then number is multiple of 3 e.g., for 612 sum of digits is 9 so it’s a multiple of 3. But this solution is not efficient. You have to get all decimal digits one by one, add them and then check if sum is multiple of 3. There is a pattern in binary representation of the number that can be used to find if number is a multiple of 3.
Read full article from Write an Efficient Method to Check if a Number is Multiple of 3 | GeeksforGeeks
No comments:
Post a Comment