The problem is to check whether the decimal representation of the given binary number is divisible by 20 or not. Take care, the number could be very large and may not fit even in long long int. The approach should be such that there are zero or minimum number of multiplication and division operations. No leading 0’s are there in the input.
Input : 101000 Output : Yes (10100)2 = (40)10 and 40 is divisible by 20. Input : 110001110011100 Output : Yes
Approach: Following are the steps:
- Let the binary string be bin.
- Let the length of bin be n.
- If bin[n-1] == ‘1’, then it is an odd number and thus not divisible by 20.
- Else check if bin[0..n-2] is divisible by 10. Refer this post.
Time Complexity: O(n), where n is the number of digits in the binary number.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Decimal representation of given binary string is divisible by 10 or not
- Decimal representation of given binary string is divisible by 5 or not
- Check if Decimal representation of an Octal number is divisible by 7
- Convert a given Decimal number to its BCD representation
- Maximum splits in binary string such that each substring is divisible by given odd number
- Maximum 0's between two immediate 1's in binary representation
- Find value of k-th bit in binary representation
- Binary representation of a given number
- XOR counts of 0s and 1s in binary representation
- 1 to n bit numbers with no consecutive 1s in binary representation.
- Binary representation of previous number
- Maximum distance between two 1's in Binary representation of N
- 1 to n bit numbers with no consecutive 1s in binary representation
- Next greater number than N with exactly one bit different in binary representation of N
- Largest number with binary representation is m 1's and m-1 0's
- Length of the Longest Consecutive 1s in Binary Representation
- Find the n-th number whose binary representation is a palindrome
- Convert numbers into binary representation and add them without carry
- Prime Number of Set Bits in Binary Representation | Set 1
- Occurrences of a pattern in binary representation of a number
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Mithun Kumar